我正在使用制表(https://pypi.org/project/tabulate/),我想用千位分隔符格式化一个数字列并右对齐。这就是我所做的,它没有正确对齐我的列。
import pandas as pd
rom tabulate import tabulate
df = pd.DataFrame([{'size':225612466, 'path': '/etc'}, {'size':66, 'path': '/home'}])
df['size'] = df['size'].apply(lambda x: "{:,}".format(x).rjust(15))
print(tabulate(df, headers='keys', tablefmt='psql', showindex=False))
+--------+-------------+
| path | size |
|--------+-------------|
| /etc | 225,612,466 |
| /home | 66 |
+--------+-------------+
我希望它是这样的:
+--------+-----------------+
| path | size |
|--------+-----------------|
| /etc | 225,612,466 |
| /home | 66 |
+--------+-----------------+
谢谢,