Python 数据框:描述单个列

Python Dataframes: Describing a single column

有没有一种方法可以将 df.describe() 应用于 DataFrame 中的一个独立列。

例如,如果我有多个列并且我使用 df.describe() - 它 returns 并描述所有列。通过研究,我知道我可以添加以下内容:

"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'"

但是我不太清楚如何用 python 代码写出来。 提前致谢。

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

或者例如

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

只需在方括号中添加列名:

df['column_name'].describe()

示例:

获取单列

df['1']

获取多列:

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

要按名称获取 单行

df.loc['B']

或按索引:

df.iloc[o]

获取特定字段

df['1']['C']

在 Pyspark DataFrame 中,您只能像这样描述一列:

df.describe("col1").toPandas()

或像这样的几列:

df.describe(["col1", "col2"]).toPandas()
import pandas as pd
data=pd.read_csv('data.csv')
data[['column1', 'column2', 'column3']].describe()

描述为table

df[['column_name']].describe()

将其描述为数据

df['column_name'].describe()