Describing certain columns of a DataFrame in Pandas
Start your free 7-days trial now!
To describe certain columns, as opposed to all columns, use the
 notation to first extract the desired columns and then use the
Consider the following DataFrame:
To describe only columns
gender agecount 3 3.000000unique 2 NaNtop male NaNfreq 2 NaNmean NaN 23.333333std NaN 5.773503min NaN 20.00000025% NaN 20.00000050% NaN 20.00000075% NaN 25.000000max NaN 30.000000
Here, note the following:
df[["gender","age"]]syntax extracts the columns
dfas a DataFrame
include=allparameter indicates that we want to compute the descriptive statistic of all columns. If this is left out, then only numeric types will be considered, and so the
gendercolumn will be ignored.