使用方法
- 首先需要安装
tabulate
:pip install tabulate
- 然后使用
dataframe.to_markdown()
即可
案例
import pandas as pd
df = pd.DataFrame([
['2021-01-01', 'hahhah', '9340do', 43, 123.23, '2021-01-01'],
['2022-02-02', 'balbal', 'jsi0-2-3', 12, 34.0, '2022-02-02'],
['2023-03-03', 'kkk', '123vd-2f', 23, 12.0, '2023-03-03'],
], columns=['time1', 'str1', 'str2', 'int1', 'float1', 'time2'])
print(df.to_markdown())
打印内容:
| | time1 | str1 | str2 | int1 | float1 | time2 |
|---:|:-----------|:-------|:---------|-------:|---------:|:-----------|
| 0 | 2021-01-01 | hahhah | 9340do | 43 | 123.23 | 2021-01-01 |
| 1 | 2022-02-02 | balbal | jsi0-2-3 | 12 | 34 | 2022-02-02 |
| 2 | 2023-03-03 | kkk | 123vd-2f | 23 | 12 | 2023-03-03 |
显示内容:
time1 | str1 | str2 | int1 | float1 | time2 | |
---|---|---|---|---|---|---|
0 | 2021-01-01 | hahhah | 9340do | 43 | 123.23 | 2021-01-01 |
1 | 2022-02-02 | balbal | jsi0-2-3 | 12 | 34 | 2022-02-02 |
2 | 2023-03-03 | kkk | 123vd-2f | 23 | 12 | 2023-03-03 |
参考
pandas.DataFrame.to_markdown Doc:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_markdown.html