简体   繁体   中英

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

这可以通过获取除字符串的前5个字符之外的所有字符来实现:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM