1

I am trying to detect Nonetype in a single cell of a 1 column, 15 row dataframe with the following:

if str(row.iloc[13][:]) is None:
     print("YES")

But this causes the error: TypeError: 'NoneType' object is not subscriptable

2
  • Why not if row.iloc[13] is None: ? Also can you explain more, what need? Commented Apr 6, 2020 at 6:59
  • do you mean if row.iloc[13] is None:? Commented Apr 6, 2020 at 6:59

1 Answer 1

1

If row is Series, then if select value by position:

row.iloc[13]

output is scalar. So cannot slice scalar value by [:]. Also if convert to string by str cannot compare by None, but by string like:

if str(row.iloc[13]) == 'None':

If want compare by None:

if row.iloc[13] is None:

Or if compare by NaN or None:

if pd.isna(row.iloc[13]):
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.