0
0
Pandasdata~30 mins

Exporting results to multiple formats in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Exporting results to multiple formats
📖 Scenario: You have collected sales data for a small store. You want to save this data in different file formats so you can share it easily with others who may use different software.
🎯 Goal: Create a small sales data table using pandas, then export it to CSV and Excel files.
📋 What You'll Learn
Create a pandas DataFrame with specific sales data
Set a filename variable for saving files
Export the DataFrame to a CSV file
Export the DataFrame to an Excel file
Print confirmation messages after each export
💡 Why This Matters
🌍 Real World
Saving data in multiple formats helps share information with different tools and users easily.
💼 Career
Data scientists often export data to CSV and Excel to communicate results with teams and clients.
Progress0 / 4 steps
1
Create the sales data DataFrame
Import pandas as pd and create a DataFrame called sales_data with these exact columns and values:
'Product': ['Apples', 'Bananas', 'Cherries'],
'Quantity': [10, 20, 15],
'Price': [0.5, 0.3, 0.8]
Pandas
Need a hint?

Use pd.DataFrame with a dictionary of lists for columns.

2
Set the filename prefix
Create a variable called filename and set it to the string 'store_sales'.
Pandas
Need a hint?

Just assign the string 'store_sales' to filename.

3
Export the DataFrame to CSV and Excel
Use sales_data.to_csv() to save the data to a CSV file named filename + '.csv' without the index. Then use sales_data.to_excel() to save the data to an Excel file named filename + '.xlsx' without the index.
Pandas
Need a hint?

Use the to_csv and to_excel methods with index=False.

4
Print confirmation messages
Print the exact messages:
"CSV file saved as store_sales.csv"
and
"Excel file saved as store_sales.xlsx".
Pandas
Need a hint?

Use two print() statements with the exact text.