I'm trying to format the Dollar Amount column to have a comma thousands separator for easier viewing, but I haven't been able to figure it out. Can someone please show me the way?
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
Notice it will convert your float
type to 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
This is a more pandorable way to get the thousands separator.
df['Dollar Amount']=df['Dollar Amount'].apply('{:,}'.format)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With