0
0
Data Analysis Pythondata~10 mins

Exporting to JSON in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to export the DataFrame to a JSON file named 'data.json'.

Data Analysis Python
df.to_json('[1]')
Drag options to blanks, or click blank then click option'
Adata.csv
Bdata.json
Cdata.txt
Ddata.xlsx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a filename with the wrong extension like .csv or .txt
Forgetting to put the filename in quotes
2fill in blank
medium

Complete the code to export the DataFrame to a JSON string instead of a file.

Data Analysis Python
json_str = df.to_json([1]=None)
Drag options to blanks, or click blank then click option'
Ato_string
Bforce_ascii
Corient
Dpath_or_buf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'orient' or 'to_string' which are unrelated to output destination
Not passing None but a filename string
3fill in blank
hard

Fix the error in the code to export only the 'name' and 'age' columns to JSON.

Data Analysis Python
df[['name', '[1]']].to_json('subset.json')
Drag options to blanks, or click blank then click option'
Aage
Bsalary
Cgender
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting columns not present in the DataFrame
Forgetting to include the second column
4fill in blank
hard

Fill both blanks to export the DataFrame to JSON with records orientation and indentation of 2 spaces.

Data Analysis Python
df.to_json('output.json', orient='[1]', indent=[2])
Drag options to blanks, or click blank then click option'
Arecords
Bcolumns
C2
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong orient like 'columns' which changes JSON structure
Using indent values that are too large or missing
5fill in blank
hard

Fill all three blanks to export the DataFrame to JSON with index excluded, using split orientation, and ASCII characters only.

Data Analysis Python
df.to_json('final.json', [1]=False, orient='[2]', force_ascii=[3])
Drag options to blanks, or click blank then click option'
Aindex
Bsplit
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to exclude index causing extra data
Using wrong orient value
Not setting force_ascii correctly