We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Info & Describe

The .head() method is good for a quick "sniff test" of a new DataFrame, but you'll also want to look at summary info about the data. This is where the .info() and .describe() methods come in.

Info

The .info() method prints a concise summary of your DataFrame.

df.info()

Prints something like this:

<class 'pandas.DataFrame'>
RangeIndex: 20 entries, 0 to 19
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype
---  ------  --------------  -----
 0   city    20 non-null     object
 1   price   20 non-null     float64
 2   sqft    19 non-null     float64
dtypes: float64(2), object(1)
memory usage: 612.0 bytes

We get a bunch of useful info at once:

  • The number of rows (in this example, 20)
  • The number of columns (3)
  • The column names and their data types (object, float64)
  • The count of non-null values in each column (sqft has 19 non-null, meaning 1 missing value)
  • The memory footprint of the DataFrame (612.0 bytes)

Describe

The .describe() method digs a bit deeper, generating descriptive statistics for numeric columns by default:

stats_df = df.describe()
print(stats_df)

This returns a new DataFrame containing the statistics. If you print it, the output will look something like this:

               price         sqft
count      20.000000    19.000000
mean   470250.000000  1575.263158
std    150939.818959   410.573696
min    225000.000000   880.000000
25%    373750.000000  1325.000000
50%    465000.000000  1550.000000
75%    548750.000000  1825.000000
max    815000.000000  2400.000000
  • count: Number of non-null (non-missing) values
  • mean: Average value
  • std: Standard deviation (how spread out the values are; higher = more variation)
  • min: Minimum (smallest) value
  • 25%: First quartile (25% of values are below this)
  • 50%: Median (middle value; half of values are above, half below)
  • 75%: Third quartile (75% of values are below this)
  • max: Maximum (largest) value

Because .describe() returns a DataFrame, you can select from it like any other DataFrame. The .loc[] indexer selects by label instead of numeric position.

stats = df.describe()
price_stats = stats["price"]
print(price_stats.loc["mean"])
# 470250.0

Assignment

SnackStack's analytics team needs the average temperature for a new batch of sensor readings, after a quick structural check. Complete the get_average_temperature function. It accepts a DataFrame, prints its info, and returns the mean temperature.