简体   繁体   中英

Pandas replace integer to empty string (Python)

I want to replace column integer values to empty strings (''). But, can not find appropriate way.

Current data     

     0
0  asd
1  9
2  gfs
3  45
4  4
5  dsf

Expected result

     0
0  asd
1  
2  gfs
3  
4  
5  dsf

Use str.isnumeric and df.where :

>>> series
0    asd
1      9
2    gfs
3     45
4      4
5    dsf
Name: 0, dtype: object

>>> series.where(~series.str.isnumeric(), '')
0    asd
1       
2    gfs
3       
4       
5    dsf
Name: 0, dtype: object

If it's a dataframe, then:

>>> df.where(~df['0'].str.isnumeric(), '')
     0
0  asd
1     
2  gfs
3     
4     
5  dsf

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