Editor

Extract Stats from describe()

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 lesson

Given a DataFrame with a 'score' column containing [80, 90, 70, 100, 85], use describe() to get the summary statistics for that column. Print the mean value using print(df['score'].describe()['mean']).

import pandas as pd
df = pd.DataFrame({'score': [80, 90, 70, 100, 85]})
# Print the mean from describe()

More Pandas DataFrame exercises

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