python - 从 python pandas 中抑制 Name dtype describe

标签 python pandas dataframe format series

假设我有

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/

相关文章:

python - 加速 Python 迭代

python - 在python中使用正则表达式提取可变长度数字

python |自动数据帧生成

python - 通过与列表比较过滤掉 panda-df 的行

python - 如何将数据帧转换为所需的格式?

r - 创建 Lollipop 图表来比较组

python - 在Python中提取数据帧的groupby值

python - 如何将dict的dict转换为指定格式的dict?

python - 如何使用 python 制作盒须图

python pandas - 删除列中的重复项并根据复杂的标准保留行