Trying to create a new column in my dataframe call "Method". Current dataFrame in the attached picture:
I'm trying to use if/elif/else as well as regex to create the new column but when I run this code, I get only the value that comes from the else statement. Why isn't this working and how can I fix it?
if 'posted' in df2.Full.astype(str) and '/ Outbound' in df2.TPrev.astype(str):
df2['Method']='Classifieds Homepage Button'
elif 'ad posted' in df2.Full.astype(str) and 'thanks' in df2.TPrev.astype(str):
df2['Method']='Header after Post'
elif 'ad posted' in df2.Full.astype(str) and '/myaccount/listing-classified Outbound' in df2.TPrev.astype(str):
df2['Method']='My Listings Button'
elif 'ad posted' in df2.Full.astype(str) and '/s/' in df2.TPrev.astype(str):
df2['Method']='SRP'
elif 'ad posted' in df2.Full.astype(str) and '/myaccount/listing-classified nan' in df2.TPrev.astype(str):
df2['Method']='My Listings Button'
elif 'ad posted' in df2.Full.astype(str) and '/sell nan nan' in df2.TPrev and '/myaccount/listing-classified nan nan' in df2.Prev.astype(str):
df2['Method']='My Listings Header'
elif 'ad posted' in df2.Full.astype(str) and '/listing/' in df2.TPrev.astype(str):
df2['Method']='Detail Page Header'
elif 'ad posted' in df2.Full.astype(str) and '/search/' in df2.TPrev.astype(str):
df2['Method']='SRP'
else:
df2['Method']='Ignore'
Aucun commentaire:
Enregistrer un commentaire