0
0
Data Analysis Pythondata~15 mins

Reading JSON (read_json) in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Reading JSON Data with pandas
📖 Scenario: You work at a small online store. The store keeps its product data in JSON format. You want to load this data into Python to analyze it easily.
🎯 Goal: Load a JSON string into a pandas DataFrame, then filter products by price.
📋 What You'll Learn
Create a JSON string variable with product data
Create a price threshold variable
Use pandas read_json to load the JSON string into a DataFrame
Filter the DataFrame to keep only products with price above the threshold
Print the filtered DataFrame
💡 Why This Matters
🌍 Real World
Many companies store data in JSON format. Loading JSON into DataFrames helps analyze and visualize data easily.
💼 Career
Data analysts and scientists often read JSON data from APIs or files to prepare data for analysis.
Progress0 / 4 steps
1
Create JSON string with product data
Create a variable called json_data that holds this exact JSON string: [{"product": "Pen", "price": 1.5}, {"product": "Notebook", "price": 3.0}, {"product": "Eraser", "price": 0.5}]
Data Analysis Python
Need a hint?

Use single quotes outside and double quotes inside for the JSON string.

2
Set price threshold
Create a variable called price_threshold and set it to 1.0
Data Analysis Python
Need a hint?

Just assign 1.0 to price_threshold.

3
Load JSON and filter products
Import pandas as pd. Use pd.read_json to load json_data into a DataFrame called df. Then create a new DataFrame called filtered_df that contains only rows where the price column is greater than price_threshold.
Data Analysis Python
Need a hint?

Use square brackets to filter the DataFrame by condition.

4
Print filtered DataFrame
Print the filtered_df DataFrame to show products with price above the threshold.
Data Analysis Python
Need a hint?

Use print(filtered_df) to display the filtered products.