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

ZJA*_*JAY 6 python pandas

使用以下代码:

predictions  = pd.DataFrame([x6,x5,x4,x3,x2,x1])
print(predictions)
Run Code Online (Sandbox Code Playgroud)

在控制台打印以下内容:

            0
0  782.367392
1  783.314159
2  726.904744
3  772.089101
4  728.797342
5  753.678877
Run Code Online (Sandbox Code Playgroud)

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

在 R 中,代码如下所示:

print(predictions, row.names = FALSE)
Run Code Online (Sandbox Code Playgroud)

yoo*_*ghm 7

print(df.to_string(index=False, header=False))
Run Code Online (Sandbox Code Playgroud)

  • 那看起来不错。你也可以在打印前做一些四舍五入,例如`df.round(2).to_string(...)` (2认同)

Ale*_*der 4

print(predictions.values.tolist())
Run Code Online (Sandbox Code Playgroud)

或者

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]
Run Code Online (Sandbox Code Playgroud)