1

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
2
  • 1
    Only integers, or any numeric-like values? Commented Aug 11, 2020 at 4:21
  • Yes, I want only string values on my data. Other values need to change to empty string. Commented Aug 11, 2020 at 4:26

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.