Editor

Predict the Output: head()

Intermediate · Predict the output · 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 lesson

What will this code print?

import pandas as pd
df = pd.DataFrame({'x': [10, 20, 30, 40, 50]})
print(df.head(2).values.tolist())
import pandas as pd
df = pd.DataFrame({'x': [10, 20, 30, 40, 50]})
print(df.head(2).values.tolist())

More Pandas DataFrame exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz