ACH*_*ACH 8 excel dataframe pandas python-3.6
我正在尝试将 Dollar Amount 列的格式设置为逗号千位分隔符以便于查看,但我一直无法弄清楚。有人可以给我指路吗?
import pandas as pd
df = pd.read_excel('filename.xlsx')
df['Dollar Amount'].head()
Index Dollar Amount
0 5721.48
1 4000.00
2 4769.00
3 824.07
4 643.60
5 620.00
Name: Dollar Amount, dtype: float64
Run Code Online (Sandbox Code Playgroud)
WeN*_*Ben 14
请注意,它会将您的float类型转换为object
df.DollarAmount.apply(lambda x : "{:,}".format(x))
Out[509]:
0 5,721.48
1 4,000.0
2 4,769.0
3 824.07
4 643.6
5 620.0
Name: DollarAmount, dtype: object
Run Code Online (Sandbox Code Playgroud)
小智 10
这是获取千位分隔符的更可行的方法。
df['Dollar Amount']=df['Dollar Amount'].apply('{:,}'.format)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22722 次 |
| 最近记录: |