我想打印整个数据框架,但我不想打印索引
另外,其中一列是datetime类型,我只想打印时间,而不是日期。
数据框架看起来像这样:
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
我要按原样打印
User ID Enter Time Activity Number
123 00:09:00 1411
123 00:18:00 893
123 00:49:00 1041
如果你想漂亮地打印数据帧,那么你可以使用表格包。
import pandas as pd
import numpy as np
from tabulate import tabulate
def pprint_df(dframe):
print tabulate(dframe, headers='keys', tablefmt='psql', showindex=False)
df = pd.DataFrame({'col1': np.random.randint(0, 100, 10),
'col2': np.random.randint(50, 100, 10),
'col3': np.random.randint(10, 10000, 10)})
pprint_df(df)
具体来说,showindex=False,顾名思义,允许不显示索引。输出如下所示:
+--------+--------+--------+
| col1 | col2 | col3 |
|--------+--------+--------|
| 15 | 76 | 5175 |
| 30 | 97 | 3331 |
| 34 | 56 | 3513 |
| 50 | 65 | 203 |
| 84 | 75 | 7559 |
| 41 | 82 | 939 |
| 78 | 59 | 4971 |
| 98 | 99 | 167 |
| 81 | 99 | 6527 |
| 17 | 94 | 4267 |
+--------+--------+--------+