如何在python中的Pandas describe函数输出中添加新行

2024-05-14 19:58:39 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的python问题

我被要求生成一个输出表,其中包含每个变量(数据中有超过10个变量)中的Nan数、min、max、mean、std、25%、50%和70%。我使用panda中的describe函数创建了describe表,它提供了我想要的所有内容,但是每个变量中的Nan的数量。我正在考虑将Nan的数量作为新行添加到由describe输出生成的输出中。在

有人能帮忙吗?在

output = input_data.describe(include=[np.number]) # this gives the table output

count_nan = input_data.isnull().sum(axis=0) # this counts the number of Nan of each variable

如何将第二个作为行添加到第一个表中?在


Tags: ofthe数据numberinputoutputdata数量
1条回答
网友
1楼 · 发布于 2024-05-14 19:58:39

可以使用^{}将新行追加到数据帧:

In [21]: output.append(pd.Series(count_nan, name='nans'))
Out[21]: 
              0         1         2         3         4
count  4.000000  4.000000  4.000000  4.000000  4.000000
mean   0.583707  0.578610  0.566523  0.480307  0.540259
std    0.142930  0.358793  0.309701  0.097326  0.277490
min    0.450488  0.123328  0.151346  0.381263  0.226411
25%    0.519591  0.406628  0.478343  0.406436  0.429003
50%    0.549012  0.610845  0.607350  0.478787  0.516508
75%    0.613127  0.782827  0.695530  0.552658  0.627764
max    0.786316  0.969421  0.900046  0.582391  0.901610
nans   0.000000  0.000000  0.000000  0.000000  0.000000

相关问题 更多 >

    热门问题