Skip to content Skip to sidebar Skip to footer

Pandas - Add Value To A Column On A For

Im trying a script and i want to add value to each row on my Column login: If the result on For is 200 i want add 'yes' to the login Column on the correct row. thank u! import pand

Solution 1:

You might do it in one single line using apply:

newdf['login'] = newdf['Site'].apply(lambda x : "yes"ifget(x).status_code == 200else"no")

Solution 2:

One way you could do it is to just iterate over the rows and add it in that way:

for i inrange(newdf.shape[0]):
   result=get(newdf.iloc[i,0])
   if result==200:
      newdf.iloc[i,1] = "yes"

etc.

Post a Comment for "Pandas - Add Value To A Column On A For"