Reputation: 51
I have dataframe like this:
Mode Small medium Large
Car 20USD 40USD 60USD
Bike 10RS 30RS 45RS
Need it be like this:
Mode Currency Small Medium Large
Car USD 20 40 60
Bike RS 10 30 45
Upvotes: 0
Views: 75
Reputation: 109
Well there's two ways to do that:
df['Currency'] = df['Small'].str.extract(r'\w+')
df['Small'] = df['Small'].str.extract(r'\d+').astype('int')
df['Medium'] = df['Medium'].str.extract(r'\d+').astype('int')
df['Large'] = df['Large'].str.extract(r'\d+').astype('int')
If everything goes right that should work.
Upvotes: 1