Python Forum
(Solved) Converting Dollar Amount Str to Int with Pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(Solved) Converting Dollar Amount Str to Int with Pandas
#1
(SOLVED)

I've found similar problems to what I am having on stackoverflow, but nothing that solves what I'm dealing with.

I'm trying to remove the Euro sign as well as convert M and K amounts to 1000000 and 1000 respectively. Parts of this code seems to work individually, but I have to execute it all at once so that the single function can determine whether the amount has an 'M' or 'K' before removing it from the value, so that it can convert it to a float afterwards and still add the same amount of zeroes.

Here is the latest iteration of what I'm trying to do in code:
Quote:def fix(x):
if 'M' in x:
return float(x.replace('[€M]', '', regex=True))*10000000
if 'K' in x:
return float(x.replace('[€K]', '', regex=True))*10000


df1 = df[['Name', 'Value', 'Wage']]
df1.apply(fix)
df1.head(6)

Thank you for anyone who can help me with this! Undecided
Reply


Messages In This Thread
(Solved) Converting Dollar Amount Str to Int with Pandas - by calvinsomething - Nov-19-2020, 12:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] duplication in pandas BSDevo 0 591 Sep-06-2023, 10:47 PM
Last Post: BSDevo
  Pandas converting date to epoch randor 2 4,008 Jul-16-2019, 02:41 AM
Last Post: scidam
  Converting string the pandas dataframe chrismc 0 2,382 Jan-24-2019, 11:07 AM
Last Post: chrismc

Forum Jump:

User Panel Messages

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