打印没有行号/索引的熊猫数据框

时间:2018-09-19 00:55:21

标签: python pandas

使用以下代码:

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

在控制台中打印以下内容:

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

如何在没有行(0-5)或列(0)索引的情况下打印predictions

在R中,代码如下:

print(predictions, row.names = FALSE)

3 个答案:

答案 0 :(得分:2)

或使用:

predictions[0].tolist()

或者可以执行以下操作:

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

或者可以这样做:

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

或要分配给字符串:

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

答案 1 :(得分:2)

print(df.to_string(index=False, header=False))

答案 2 :(得分:1)

print(predictions.values.tolist())

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]
相关问题