[英]Pandas replace integer to empty string (Python)
I want to replace column integer values to empty strings ('').我想将列 integer 值替换为空字符串('')。 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
:使用
str.isnumeric
和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:如果是 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.