gpt4 book ai didi

python - 从 python pandas 中抑制 Name dtype describe

转载 作者:太空狗 更新时间:2023-10-29 20:49:07 26 4
gpt4 key购买 nike

假设我有

r = pd.DataFrame({'A':1 ,
'B':pd.Series(1,index=list(range(4)),dtype='float32')})

r['B'].describe()[['mean','std','min','max']] 给出输出:

mean    1.0
std 0.0
min 1.0
max 1.0
Name: B, dtype: float64

但是从上面的输出来看,我应该如何去掉或抑制最后一行 "Name:B, dtype: float64 "

我想出了一个方法来实现这一目标

x=r['B'].describe()[['mean','std','min','max']]
print "mean ",x['mean'],"\nstd ",x['std'],"\nmin ",x['min'],"\nmax ",x['max']

它给出了所需的输出:

mean  1.0 
std 0.0
min 1.0
max 1.0

是否有任何清洁器可以直接从 pd.describe() 实现此输出

最佳答案

如果需要输出为DataFrame 添加reset_index :

x=r['B'].describe()[['mean','std','min','max']].reset_index()
print (x)
index B
0 mean 1.0
1 std 0.0
2 min 1.0
3 max 1.0

然后使用DataFrame.to_string :

print (x.to_string(header=None, index=None))
mean 1.0
std 0.0
min 1.0
max 1.0

关于python - 从 python pandas 中抑制 Name dtype describe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40278845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com