Build a DataFrame from a Dictionary
Intermediate · Write the code · from Pandas: Create, Load, and Explore DataFrames
From the lesson: Pandas: Create, Load, and Explore DataFrames
You have a spreadsheet with 10,000 rows of sales data. You need to find every order over $500, group them by region, and calculate the average. In Excel, that takes a pivot table, a filter, and a lot of clicking. In pandas, it takes three lines of code.
Read the lessonCreate a DataFrame called df with three columns:
'fruit': ['Apple', 'Banana', 'Cherry']'price': [1.2, 0.5, 2.0]'stock': [100, 200, 50]Print the column names as a list using df.columns.tolist().
import pandas as pd
# Create the DataFrame
More Pandas DataFrame exercises
- Create a Named SeriesIntermediate
- DataFrame from RecordsIntermediate
- Predict the Output: head()Intermediate
- Add a Computed ColumnIntermediate
- Fix the Bug: Column SelectionIntermediate
- Extract Stats from describe()Intermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz