pandas 打印没有行号/索引的熊猫数据框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52396477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:02:27 来源:igfitidea点击:
Printing a pandas dataframe without row number/index
提问by ZJAY
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?
如何在predictions
没有行 (0-5) 或列 (0) 索引的情况下打印?
In R the code would look like:
在 R 中,代码如下所示:
print(predictions, row.names = FALSE)
回答by yoonghm
print(df.to_string(index=False, header=False))
回答by U10-Forward
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())
回答by Alexander
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]