5

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)

smci
  • 26,085
  • 16
  • 96
  • 138
atomh33ls
  • 23,172
  • 18
  • 91
  • 149
  • How are you appending this to a text file? Eg when using `to_csv` this will not appear in the text output, it is only in the console display. – joris Jun 18 '14 at 22:00
  • 1
    The normal console answer would probably be `df.to_string()`, but if you are appending it to a text file you should definitely use `to_csv` (with `delimiter` set to some spaces). – U2EF1 Jun 18 '14 at 22:00
  • I am using `f = open('myfile.txt', 'w')` and `f.write(str(c) + '\n\n')`. I'll give `to_csv` a go, thanks. – atomh33ls Jun 18 '14 at 22:07
  • I could be wrong bu it seems that you can't append with `to_csv` – atomh33ls Jun 18 '14 at 22:10
  • 2
    You can just pass arg `mode='a'` – EdChum Jun 18 '14 at 22:13

1 Answers1

5

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).

Community
  • 1
  • 1
Andy Hayden
  • 291,328
  • 80
  • 565
  • 500