0

I would like to differentiate an empty string with certain lengths and a regular string such as G1234567. The length of the empty string right now in my dataset is 8 but I would not guarantee all future empty string will still have length of 8.

This is what the column looks like when I print it out:

0               
1               
2               
3               
4               
  
9461    G6000000
9462    G6000001
9463    G6000002
9464    G6000003
9465    G6000004
Name: Sub_ID, Length: 9466, dtype: object

If I apply pd.isnull() on the entire column, I will have a mask populated with all False. I would like to ask if there is anyway for me to differentiate between an empty string with certain lengths and a string that is actually populated with something.

Thank you so much for your help!

1 Answer 1

1

The following creates a mask for all the cells in your DataFrame (df) that are just empty strings (strings that only contain whitespaces):

df.applymap(lambda column: column.isspace())
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for pointing out the isspace() method. I applied the method directly to the column instead of the whole dataframe and it works perfectly. Thanks again!

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.