Issue
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 pandas as pd
from requests import get
lista = pd.read_csv('sites.csv', sep=',')
df = pd.DataFrame(lista, columns=['Site', 'Login'])
newdf = df.assign(Site=df['Site'].map(str) + 'login')
for i in newdf['Site']:
result = get(i)
if result.status_code == 200:
print(i + '' ' login page')
elif result.status_code == 404:
print(i + '' ' not a login page')
else :
print(i + '' ' Not a login page')enter code here
the csv data:
Site, Login
https://www.site1.com.br/,
https://www.site2.com.br/,
https://www.site3.com.br/,
Solution
You might do it in one single line using apply
:
newdf['login'] = newdf['Site'].apply(lambda x : "yes" if get(x).status_code == 200 else "no")
Answered By - Sebastien D
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.