8

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)
ZJAY
  • 2,517
  • 9
  • 32
  • 51

3 Answers3

14
print(df.to_string(index=False, header=False))
yoonghm
  • 4,198
  • 1
  • 32
  • 48
4
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]
Alexander
  • 105,104
  • 32
  • 201
  • 196
  • That returns: [[782.3673915172626], [783.314158724909], [726.9047442598429], [772.0891010290351], [728.7973416236138], [753.67887656913]] - I'm not looking to return brackets or commas, just numbers – ZJAY Sep 19 '18 at 00:58
  • I just answered this related question about 10 mins ago. https://stackoverflow.com/questions/52396315/printing-numpy-arrays-without-brackets – Alexander Sep 19 '18 at 01:00
2

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())
U13-Forward
  • 69,221
  • 14
  • 89
  • 114