Concept Flow - Exporting results to multiple formats
Create DataFrame
Choose export format
Export to CSV
Export to Excel
Export to JSON
Export to HTML
File saved in chosen format
Start with a DataFrame, pick a format, then export and save the file.
import pandas as pd data = {'Name': ['Anna', 'Bob'], 'Age': [28, 34]} df = pd.DataFrame(data) df.to_csv('output.csv', index=False)
| Step | Action | DataFrame State | File Created | Notes |
|---|---|---|---|---|
| 1 | Create DataFrame | {'Name': ['Anna', 'Bob'], 'Age': [28, 34]} | No | DataFrame with 2 rows and 2 columns created |
| 2 | Call df.to_csv('output.csv', index=False) | Same as step 1 | output.csv | CSV file saved without index column |
| 3 | Call df.to_excel('output.xlsx', index=False) | Same as step 1 | output.xlsx | Excel file saved without index column |
| 4 | Call df.to_json('output.json') | Same as step 1 | output.json | JSON file saved with default orientation |
| 5 | Call df.to_html('output.html', index=False) | Same as step 1 | output.html | HTML file saved without index column |
| 6 | End of export operations | No change | All files created | All chosen formats exported successfully |
| Variable | Start | After CSV Export | After Excel Export | After JSON Export | After HTML Export | Final |
|---|---|---|---|---|---|---|
| df | {'Name': ['Anna', 'Bob'], 'Age': [28, 34]} | No change | No change | No change | No change | No change |
| output.csv | Not created | Created | Created | Created | Created | Created |
| output.xlsx | Not created | Not created | Created | Created | Created | Created |
| output.json | Not created | Not created | Not created | Created | Created | Created |
| output.html | Not created | Not created | Not created | Not created | Created | Created |
Exporting DataFrame to files:
Use df.to_csv('file.csv', index=False) for CSV
Use df.to_excel('file.xlsx', index=False) for Excel
Use df.to_json('file.json') for JSON
Use df.to_html('file.html', index=False) for HTML
index=False avoids saving row numbers
Multiple exports can be done one after another