0

我有一个数据框,11 列 18k 行。最后一列是 1 或 0,但是当我使用 .describe() 时,我得到的只是

count     19020
unique        2
top           1
freq      12332
Name: Class, dtype: int64

与平均值、标准差等的实际统计分析相反。

有没有办法做到这一点?

4

2 回答 2

1

你可以使用

# percentile list 
perc =[.20, .40, .60, .80] 
  
# list of dtypes to include 
include =['object', 'float', 'int']

data.describe(percentiles = perc, include = include) 

您的数据框在哪里data(重点)。

由于您是堆栈新手,我可能会建议您包含一些实际代码(即显示您如何以及如何使用您的方法的内容)。你会得到更好的答案

于 2020-10-16T14:06:35.397 回答
1

如果您的数字 (0, 1) 列没有被 自动拾取.describe(),可能是因为它实际上没有被编码为intdtype。您可以在该方法的文档.describe()中看到这一点,它告诉您默认include参数仅适用于数字类型:

无(默认):结果将包括所有数字列。

我的建议如下:


df.dtypes # check datatypes
df['num'] = df['num'].astype(int) # if it's not integer, cast it as such

df.describe(include=['object', 'int64']) # explicitly state the data types you'd like to describe

也就是说,首先检查数据类型(我假设该列被调用num并且 dataframe df,但可以随意替换为正确的)。如果此指示符/(0,1) 列确实未编码为int/integer 类型,则使用.astype(int). 然后,您可以自由使用df.describe()甚至指定要包含在描述输出中的数据类型的列,以进行更细粒度的控制。

于 2020-10-16T14:14:04.783 回答