2

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

2
  • 2
    Try this : dataframe.replace({ "Área " : "" }, regex=True) Commented Nov 15, 2015 at 20:32
  • Great. It works. I don't understand why....Thanks Commented Nov 15, 2015 at 20:40

1 Answer 1

3

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

df['area'] = [s[-4:] for s in df['area']]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.