打印 pandas 数据框时禁止描述性输出 [英] Suppress descriptive output when printing pandas dataframe
本文介绍了打印 pandas 数据框时禁止描述性输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有数据框,c
:
a=np.random.random((6,2))
c=pd.DataFrame(a)
c.columns=['A','B']
打印第0行的值:
print c.loc[(0),:]
导致:
A 0.220170
B 0.261467
Name: 0, dtype: float64
我想禁止显示Name: 0, dtype: float64
行,这样我就可以得到:
I would like to suppress the Name: 0, dtype: float64
line so that I just get:
A 0.220170
B 0.261467
有人知道吗?
(n.b.我将其附加到文本文件中)
(n.b. I am appending this to a text file)
推荐答案
您可以调整Series的__unicode__
方法:
You can tweak the __unicode__
method for a Series:
In [11]: s = pd.Series([1, 2])
In [12]: s
Out[12]:
0 1
1 2
dtype: int64
In [13]: pd.Series.__unicode__ = pd.Series.to_string
In [14]: s # same with print
Out[14]:
0 1
1 2
要附加到csv,请使用附加模式(请参见此或此问题). em>
To append to a csv use append mode (see this or this question).
这篇关于打印 pandas 数据框时禁止描述性输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文