Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Dataframes: Describing a single column

Is there a way I can apply df.describe() to just an isolated column in a DataFrame.

For example if I have several columns and I use df.describe() - it returns and describes all the columns. From research, I understand I can add the following:

"A list-like of dtypes : Limits the results to the provided data types. To limit the result to numeric types submit numpy.number. To limit it instead to object columns submit the numpy.object data type. Strings can also be used in the style of select_dtypes (e.g. df.describe(include=['O'])). To select pandas categorical columns, use 'category'"

However I don't quite know how to write this out in python code. Thanks in advance.

like image 874
Gitliong Avatar asked May 04 '18 01:05

Gitliong


1 Answers

Just add column name in square braquets:

df['column_name'].describe()

Example:

enter image description here

To get a single column:

df['1']

To get several columns:

df[['1','2']]

To get a single row by name:

df.loc['B']

or by index:

df.iloc[o]

To get a specific field:

df['1']['C']
like image 77
ma-ku Avatar answered Oct 03 '22 07:10

ma-ku