Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress descriptive output when printing pandas dataframe

Say I have dataframe, c:

a=np.random.random((6,2))
c=pd.DataFrame(a)
c.columns=['A','B']

printing row 0 values:

print c.loc[(0),:]

results in:

A    0.220170
B    0.261467
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

Does anyone know how?

(n.b. I am appending this to a text file)

like image 819
atomh33ls Avatar asked Jun 18 '14 21:06

atomh33ls


1 Answers

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

To append to a csv use append mode (see this or this question).

like image 149
Andy Hayden Avatar answered Oct 11 '22 17:10

Andy Hayden