禁止从python pandas 名称dtype描述 [英] suppress Name dtype from python pandas describe

查看:192
本文介绍了禁止从python pandas 名称dtype描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有

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


$ b描述()[['mean','std','min','max']] 给出了一个 $ b

r ['B'输出:

 平均值1.0 
std 0.0
分钟1.0
最大值1.0
名称:B,dtype:float64

但是从上面的输出中,我该如何摆脱或禁止最后一行名称:B,dtype:float64



方式来实现这个

  x = r ['B']。describe()[['mean','std', 'min','max']] 
printmean,x ['mean'],\\\
std,x ['std'],\ nmin,x ['min'] ,\\\
max,x ['max']

给出所需的输出: p>

 平均值1.0 
std 0.0
最小值1.0
最大值1.0

直接从pd.describe()如果需要输出为 DataFrame 添加

org / pandas-docs / stable / generated / pandas.DataFrame.reset_index.htmlrel =nofollow> 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

<$ p $
的意思是1.0
std 0.0
分1.0
最大1.0 $ b $打印(x.to_string(header = None,index = None) b


Lets say I have

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

And r['B'].describe()[['mean','std','min','max']] gives an output :

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

But from the above output , how should I get rid or suppress the last line " Name:B, dtype: float64 "

I figured out one way to achieve this

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

which gives the desired output :

mean  1.0 
std  0.0 
min  1.0 
max  1.0 

Is there any cleaner to achieve this output directly from pd.describe( )

解决方案

If need output as DataFrame add 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

And then use DataFrame.to_string:

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

这篇关于禁止从python pandas 名称dtype描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆