Python Dataframes: Describing a single column

做~自己de王妃 提交于 2019-12-06 22:40:23

问题


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.


回答1:


Just add column name in square braquets:

df['column_name'].describe()

Example:

To get single column:

df['1']

To get few column:

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

To get single row:

df.loc['B'] by row name or df.iloc[o] by index.

To get precised field:

df['1']['C']




回答2:


import pandas as pd
data = pd.read_csv("ad.data", header=None)
data[111].describe()

or for example

lastindice = data[data .columns[-1]]
lastindice.describe()


来源:https://stackoverflow.com/questions/50165953/python-dataframes-describing-a-single-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!