簡體   English   中英

Pandas 將 integer 替換為空字符串(Python)

[英]Pandas replace integer to empty string (Python)

我想將列 integer 值替換為空字符串('')。 但是,找不到合適的方法。

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

使用str.isnumericdf.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

如果是 dataframe,則:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM