谢谢你的考虑。
总结问题
当我从excel转到减价时,我使用熊猫库。
将excel中的clipboard.
标记表)中的数据
来自pd.to_markdown的Str也应用了对齐。
但是,当我通过pd.to_markdown生成str时,我想删除对齐表中的标记。
以下是一些例子。
剪贴板上的文本
post_it width height
653 51 38
654 76 76
656 76 51
657 102 76
import pandas as pd
df=pd.read_clipboard()
markdown_table=df.to_markdown(index=False)
print(df)
post_it width height
0 653 51 38
1 654 76 76
2 656 76 51
3 657 102 76
print(markdown_table)
我从pd.to_markdown那里得到的
| post_it | width | height |
|----------:|--------:|---------:|
| 653 | 51 | 38 |
| 654 | 76 | 76 |
| 656 | 76 | 51 |
| 657 | 102 | 76 |
我想要pd.to_markdown的数据
没有冒号2行
| post_it | width | height |
|-----------|---------|----------|
| 653 | 51 | 38 |
| 654 | 76 | 76 |
| 656 | 76 | 51 |
| 657 | 102 | 76 |
发布于 2022-08-10 01:20:59
to_markdown()
方法有一个tablefmt
参数。
这看起来像你想要的:
print(df.to_markdown(tablefmt="github", index=False))
# Output
| post_it | width | height |
|-----------|---------|----------|
| 653 | 51 | 38 |
| 654 | 76 | 76 |
| 656 | 76 | 51 |
| 657 | 102 | 76 |
如果这不是您想要的,有许多格式可供选择。它们列在文档中:https://github.com/astanin/python-tabulate
https://stackoverflow.com/questions/73299563
复制相似问题