vendredi 4 août 2017

Can't evaluate column for empty values

I have read 20+ threads on this, and am still coming up empty (no pun intended).

I have a pandas dataframe df_s, which has a column that contains dates at iloc[:,8]. I am trying to add a new column to the dataframe with a value (yes/no) based on whether there is a value in the other column or not.

This is what I have been trying:

CDRFormUp = []
for row in df_s.iloc[:,8]:
    if row=="":
            CDRFormUp.append('No')
    else:
            CDRFormUp.append('Yes')
df_s['CDR Form Up'] = CDRFormUp

CDRFormUp would be the new column. I'm running every row in the dataframe, and checking to see if the value in the column is anything.

I have tried...

if row <>"":
if row == "":
if row is None:
if row:
if row>0:

Nothing is working. The column contains dates and empty cells and text. For example, the value in this column in the first row is "CDF Form", in the second row it is blank, in the third row it is "4865" or something like that.

If I set the iloc to a different column that just contains Country names, and set the condition to "Country = "Italy", it properly adds the "Yes" or "No" to the new column for each row...so it's not a wrong iloc or something else.

Any help would be incredibly appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire