0
0
Pandasdata~10 mins

Reading JSON with read_json in Pandas - 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 pandas DataFrame.

Pandas
import pandas as pd

df = pd.[1]('data.json')
Drag options to blanks, or click blank then click option'
Aread_excel
Bread_csv
Cread_table
Dread_json
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Forgetting to import pandas
Using read_excel for JSON files
2fill in blank
medium

Complete the code to read JSON data from a string using pandas.

Pandas
import pandas as pd

json_str = '{"name": ["Alice", "Bob"], "age": [25, 30]}'
df = pd.read_json([1])
Drag options to blanks, or click blank then click option'
A'data.json'
Bjson_file
Cjson_str
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a filename string instead of the JSON string variable
Not using quotes correctly around the JSON string
Using a variable name that does not exist
3fill in blank
hard

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

Pandas
import pandas as pd

df = pd.read_json('data.json', [1]='records')
Drag options to blanks, or click blank then click option'
Aorient
Bformat
Cstyle
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'format' or 'style'
Misspelling 'orient'
Passing wrong values to the parameter
4fill in blank
hard

Fill both blanks to create a DataFrame from JSON data and display the first rows.

Pandas
import pandas as pd

json_path = 'data.json'
df = pd.[1](json_path)
print(df.[2]())
Drag options to blanks, or click blank then click option'
Aread_json
Bread_csv
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Using tail() instead of head() to preview data
Forgetting parentheses after head or tail
5fill in blank
hard

Fill all three blanks to read JSON data, select a column, and convert it to a list.

Pandas
import pandas as pd

df = pd.[1]('data.json')
names = df[[2]].[3]()
Drag options to blanks, or click blank then click option'
Aread_json
B'name'
Ctolist
D'age'
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_json
Selecting the wrong column name
Using to_list() instead of tolist()