mardi 19 septembre 2017

pandas conditional statements and adding columns

I am using Pandas to sort through an excel spreadsheet. I would like to execute an if/elif function to return a string in a new column within my dataframe. I am trying to return a new column named "action" that returns a string based off time values.

state     time      
 ca         1
 ca         5
 ca         7
 ca         10

for rows in df:

 if df[time]>=1:
    return "do nothing"

 elif df[time]<=5:
     return "add more"

 elif df[time]<=10:
      return "add less"

  else:
      return "error"

Aucun commentaire:

Enregistrer un commentaire