Python Forum
thousands separator format on df column
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
thousands separator format on df column
#1
Dear Python Experts,
 
I an trying to convert my PopEst column so a thousands separator gets added.
 
def thirteen():
    Top15 = answer_one()
    Top15['PopEst'] = Top15['Energy Supply'] / Top15['Energy Supply per Capita']
    PopEst = Top15.ix[:,20]
    return PopEst     #'{:,}'.format(13213) #return '13,213'
answer_thirteen()
 
The function '{:,}'.format(13213) #return '13,213' works fine when I put a number between the parenthesis myself
but I need it applied to my dataframe column "PopEst". I could not find a way to do that.
Is that possible?
Many thanks for any hints.
Reply
#2
PopEst.apply("{:,}".format)
Reply
#3
Hello!
It's a bit off topic but...
In Python 3.6 for readability you can use underscore as thousands separator. Like this: a_mil = 1_000_000. Yet this is a valid number and is threated as 1000000. More here.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020