How to insert a comma as a thousands separator in a pandas dataframe column?
问题 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 回答1: Notice it will convert your float type to object df.DollarAmount.apply(lambda x : "{:,}".format(x)) Out[509]: 0 5