Exporting to a File

1. Export to CSV

A comma-separated values file is widely used and easy to work with.

# Syntax for exporting to a CSV file 
df.to_csv('filename.csv', index=False, sep=',', encoding='utf-8')`

2. Export to Excel

For exporting to Excel spreadsheets.

# Syntax for exporting to an Excel file 
df.to_excel('filename.xlsx', index=False, sheet_name='Sheet1', engine='openpyxl')`

3. Export to JSON

For structured data in JSON format.

# Syntax for exporting to a JSON file 
df.to_json('filename.json', orient='records', lines=True)`

4. Export to Parquet

For fast, columnar storage with Parquet files.

# Syntax for exporting to a Parquet file 
df.to_parquet('filename.parquet', index=False, engine='pyarrow')

5. Export to SQL

To write the DataFrame to a database.

df.to_sql('table_name', con=connection_string_to_db, if_exists='replace', index=False)
Powered by Forestry.md