[英]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
>>> 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.