Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to check if tuple item is nan

I have the below for loop and am try to check first if the tuple(row) item in position 10 is Nan

i=0
for row in df.iterrows():
    if row[1][10] != None:
        names = row[1][10].split(',')
        for name in names:
            df2.loc[i,:] = row[1][:]
            i=i+1
    else:
        i=i+1

I thought I could use if row[1][10] != None: but it doesnt seem to work, anyone know the solution?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Can use pd.isnull(row[1][10]) instead of if row[1][10] != None.

Example:

i=0
for row in df.iterrows():
    if pd.isnull(row[1][10]):
        df2.loc[i,:] = row[1][:]
        i=i+1
    else:
        names = row[1][10].split(',')
        for name in names:
            df2.loc[i,:] = row[1][:]
            df2.loc[i,'name'] = name
            i=i+1

Also please do give feedback about this solution.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading