0
0
Data Analysis Pythondata~10 mins

Reading JSON (read_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 read a JSON file into a DataFrame.

Data Analysis Python
import pandas as pd
df = pd.[1]('data.json')
print(df.head())
Drag options to blanks, or click blank then click option'
Aread_table
Bread_csv
Cread_json
Dread_excel
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Using read_excel for JSON files
2fill in blank
medium

Complete the code to read a JSON string into a DataFrame.

Data Analysis Python
import pandas as pd
json_str = '{"name": ["Alice", "Bob"], "age": [25, 30]}'
df = pd.[1](json_str)
print(df)
Drag options to blanks, or click blank then click option'
Aread_html
Bread_csv
Cread_sql
Dread_json
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use read_csv for JSON strings
Using read_html or read_sql which are unrelated
3fill in blank
hard

Fix the error in the code to correctly read a JSON file with lines.

Data Analysis Python
import pandas as pd
df = pd.read_json('data.json', [1]=True)
print(df.head())
Drag options to blanks, or click blank then click option'
Achunksize
Blines
Corient
Dindex_col
Attempts:
3 left
💡 Hint
Common Mistakes
Using chunksize instead of lines
Using orient or index_col which do not fix this error
4fill in blank
hard

Fill both blanks to read a JSON file and set the correct orientation.

Data Analysis Python
import pandas as pd
df = pd.read_json('data.json', [1]='[2]')
print(df.head())
Drag options to blanks, or click blank then click option'
Aorient
Blines
Crecords
Dcolumns
Attempts:
3 left
💡 Hint
Common Mistakes
Using lines as parameter name instead of orient
Using columns instead of records for orientation
5fill in blank
hard

Fill all three blanks to read a JSON string with lines and convert it to a DataFrame.

Data Analysis Python
import pandas as pd
json_str = '{"name": "Alice", "age": 25}\n{"name": "Bob", "age": 30}'
df = pd.read_json([1], [2]=[3])
print(df)
Drag options to blanks, or click blank then click option'
Ajson_str
Blines
CTrue
Dorient
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable name
Not using lines=True for JSON lines
Using orient instead of lines parameter