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