Printing a pandas dataframe without row number/index

Viewed 28823

Using the following code:

predictions  = pd.DataFrame([x6,x5,x4,x3,x2,x1])
print(predictions)

Prints the following in the console:

            0
0  782.367392
1  783.314159
2  726.904744
3  772.089101
4  728.797342
5  753.678877

How do I print predictions without row (0-5) or column (0) indexes?

In R the code would look like:

print(predictions, row.names = FALSE)
3 Answers
print(df.to_string(index=False, header=False))
print(predictions.values.tolist())

Or

df = pd.DataFrame(np.random.randn(5, 3), columns=list('ABC'))

>>> for row in df.values: print(row)
[-1.09989127 -0.17242821 -0.87785842]
[ 0.04221375  0.58281521 -1.10061918]
[ 1.14472371  0.90159072  0.50249434]
[ 0.90085595 -0.68372786 -0.12289023]
[-0.93576943 -0.26788808  0.53035547]

Or use:

predictions[0].tolist()

Or can do something like:

'\n'.join(map(str,predictions[0].tolist()))

Or can do:

for i in str(df).splitlines()[1:]:
    print(i.split(None,1)[1])

Or want to assign to string:

s=''
for i in str(df).splitlines()[1:]:
    s+=i.split(None,1)[1]+'\n'
print(s.rstrip())
Related