13

I have a pandas dataframe that contains a mix of categorical and numeric columns. By default, df.describe() returns only a summary of the numerical data (describing those columns with count, mean, std, min, quantiles, max)

when iterating through all the columns in the df and describing them individually as [df[c].describe() for c in df.columns] the description is returned based off of specific column dtype; i.e. numerical summary for int and float and categoric summary for object

Does any one know of a succinct way of describing all columns as categorical with count, unique, top, freq?

jpp
  • 159,742
  • 34
  • 281
  • 339
Zahra
  • 6,798
  • 9
  • 51
  • 76

3 Answers3

15

a slightly shorter version of the answer:

df.describe(include = 'object')
IndPythCoder
  • 693
  • 6
  • 10
13

following converts all columns to object type then describes them:

df.astype('object').describe()

for cleaner view try:

df.astype('object').describe().transpose()
Zahra
  • 6,798
  • 9
  • 51
  • 76
0

Additionally, if YOU want to see descriptions of all columns together(including categorical). you can use:

df.describe(include='all')
Saurav
  • 163
  • 2
  • 4