hernanavella
hernanavella

Reputation: 5552

How to replace part of a string in Pandas?

I have this dataframe:

    area        baths   hab     date                    price
0   Área 45m2   Baños 2 Hab. 1  Publicado: 14/11/2015   $1,250,000
1   Área 60m2   Baños 2 Hab. 1  Publicado: 14/11/2015   $2,400,000
2   Área 52m2   Baños 2 Hab. 1  Publicado: 14/11/2015   $240,000,000
3   Área 48m2   Baños 1 Hab. 1  Publicado: 14/11/2015   $1,900,000
4   Área 47m2   Baños 1 Hab. 1  Publicado: 14/11/2015   $2,300,000

dataframe.dtypes

area     object
baths    object
hab      object
date     object
price    object
dtype: object

In the column 'area', I'm trying to get rid of the part of the string 'Área ', so I tried:

dataframe.replace('Área ', '', regex=True)

Nothing happens. Never worked with text in pandas. What I'm I doing wrong?.

Thanks

Pandas '0.16.2' Python 2.7

Upvotes: 2

Views: 1512

Answers (1)

Blue Moon
Blue Moon

Reputation: 4651

this works by taking everything but the first 5 characters of the strings:

df['area'] = [s[-4:] for s in df['area']]

Upvotes: 3

Related Questions