[翻译]  How to print pandas DataFrame without index

[CHINESE]  如何在没有索引的情况下打印pandas DataFrame


I want to print the whole dataframe, but I don't want to print the index

我想打印整个数据帧,但我不想打印索引

Besides, one column is datetime type, I just want to print time, not date.

另外,一列是datetime类型,我只想打印时间,而不是日期。

The dataframe looks like:

数据框如下所示:

   User ID           Enter Time   Activity Number
0      123  2014-07-08 00:09:00              1411
1      123  2014-07-08 00:18:00               893
2      123  2014-07-08 00:49:00              1041

I want it print as

我希望它打印为

User ID   Enter Time   Activity Number
123         00:09:00              1411
123         00:18:00               893
123         00:49:00              1041

3 个解决方案

#1


87  

print df.to_string(index=False)

#2


15  

print(df.to_csv(sep='\t', index=False))

Or possibly:

或者可能:

print(df.to_csv(columns=['A', 'B', 'C'], sep='\t', index=False))

#3


1  

If you just want a string/json to print it can be solved with:

如果你只想要一个字符串/ json打印它可以解决:

print(df.to_string(index=False))

打印(df.to_string(指数= FALSE))

Buf if you want to serialize the data too or even send to a MongoDB, would be better to do something like:

如果你想序列化数据或甚至发送到MongoDB,最好是做以下事情:

document = df.to_dict(orient='list')

document = df.to_dict(orient ='list')

There are 6 ways by now to orient the data, check more in the panda docs which better fits you.

现在有6种方法来定位数据,在更适合您的熊猫文档中查看更多内容。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号