Challenge - 5 Problems
Export Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this CSV export code?
Given the DataFrame below, what will be the content of the CSV file after running the code?
Pandas
import pandas as pd df = pd.DataFrame({'Name': ['Alice', 'Bob'], 'Age': [25, 30]}) df.to_csv('output.csv', index=False)
Attempts:
2 left
💡 Hint
Check the effect of index=False in to_csv method.
✗ Incorrect
Using index=False in to_csv removes the row index from the output file, so only the columns and their values appear.
❓ data_output
intermediate2:00remaining
What is the JSON output of this DataFrame export?
What is the JSON string produced by this code?
Pandas
import pandas as pd df = pd.DataFrame({'City': ['NY', 'LA'], 'Population': [8000000, 4000000]}) json_str = df.to_json(orient='records') print(json_str)
Attempts:
2 left
💡 Hint
The 'records' orient outputs a list of dictionaries, one per row.
✗ Incorrect
The 'records' orient converts each row to a dictionary, then outputs a list of these dictionaries as JSON.
❓ visualization
advanced2:30remaining
Which option correctly exports a DataFrame to an Excel file with multiple sheets?
You want to save two DataFrames to one Excel file, each in a separate sheet. Which code does this correctly?
Pandas
import pandas as pd df1 = pd.DataFrame({'A': [1, 2]}) df2 = pd.DataFrame({'B': [3, 4]})
Attempts:
2 left
💡 Hint
Use ExcelWriter context manager to write multiple sheets.
✗ Incorrect
Using ExcelWriter as a context manager allows writing multiple sheets to the same Excel file without overwriting.
🔧 Debug
advanced2:00remaining
What error does this code raise when exporting to CSV?
What error occurs when running this code?
Pandas
import pandas as pd df = pd.DataFrame({'X': [1, 2]}) df.to_csv('output.csv', sep=';') df.to_csv('output.csv', sep=',', index='no')
Attempts:
2 left
💡 Hint
Check the type of the 'index' argument in the second to_csv call.
✗ Incorrect
The 'index' parameter expects a boolean, but 'no' is a string, causing a ValueError.
🚀 Application
expert3:00remaining
How to export a DataFrame to both CSV and JSON formats in one script?
You have a DataFrame and want to save it as 'data.csv' and 'data.json' files. Which code does this correctly?
Pandas
import pandas as pd df = pd.DataFrame({'Name': ['Tom', 'Jerry'], 'Score': [88, 92]})
Attempts:
2 left
💡 Hint
Check parameters for both to_csv and to_json methods.
✗ Incorrect
to_csv uses index=False to omit row numbers; to_json uses orient='records' to get list of dicts format.