-2

I want to strip and separate values from a column to another column in Pandas dataframe. Te current values are like

df['column']

14.535.00
14.535.00
14.535.00

I want to remove the 00 after second dot(.) and store them in another column df['new_column'] as int values so that I could perform arithmetic operations

cs95
  • 379,657
  • 97
  • 704
  • 746
Abhinav Kumar
  • 177
  • 2
  • 5
  • 22

1 Answers1

1

Edit 1: Seems like apply is always bad, seems like a more accepted solution is to use list comprehensions.

df['new_column'] = [str(x).split('.')[-1] for x in df.iloc[:,0]]

DON'T DO WHAT'S BELOW

I think this is a good instance for using apply. You might not need the str call.

What this is doing is taking the values in your column (aka a Series) and applying a function to them. The function takes each item, makes it a string, splits on the period, and grabs the last value. We then store the results of all this into a new column.

df['new_column'] = df['column'].iloc[:,0].apply(lambda x: str(x).split('.')[-1])

should result in something like what you want

bravosierra99
  • 1,331
  • 11
  • 23