0

I have a pandas series like the below, as it shows, I was able to format the float values to have commas using lambda x: "{,}".format(x)

Country
China                1,367,645,161.2903225
India                1,276,730,769.2307692
United States         317,615,384.61538464
Brazil                205,915,254.23728815
Russian Federation           143,500,000.0
Japan                 127,409,395.97315437
Germany                80,369,696.96969697
Iran                   77,075,630.25210084
United Kingdom        63,870,967.741935484
France                 63,837,349.39759036
Italy                 59,908,256.880733944
South Korea           49,805,429.864253394
Spain                   46,443,396.2264151
Canada                 35,239,864.86486486
Australia             23,316,017.316017315
Name: PopEst, dtype: float64

however the problem is when I try to convert it to string using

dp_one['PopEst'] = dp_one['PopEst'].astype("string")

I am then losing the format (commas for thousands), how can I convert it to string while keeping the comma format ?

Note: there are some questions and answers on SOF for formatting float to have commas, but nothing I found for maintaining the format when converting to string

osama yaccoub
  • 1,884
  • 2
  • 17
  • 47

0 Answers0