I have a column let's say 'Match Place'
in which there are entries like 'MANU @ POR'
, 'MANU vs. UTA'
, 'MANU @ IND'
, 'MANU vs. GRE'
etc. So my columns have 3 things in its entry, the 1st name is MANU
i.e, 1st country code, 2nd is @/vs.
and 3rd is again 2nd country name. So what I wanna do is if '@'
comes in any entry of my column I want is to be changed to 'away'
and if 'vs.'
comes in replace whole entry to 'home'
like 'MANU @ POR' should be changed to 'away'
and 'MANU vs. GRE' should be changed to 'home'
although I wrote some code to do so using for, if, else but it's taking a way too long time to compute it and my total rows are 30697 so is there any other way to reduce time below I'm showing you my code pls help
for i in range(len(df)):
if is_na(df['home/away'][i]) == True:
temp = (df['home/away'][i]).split()
if temp[1] == '@':
df['home/away'][i] = 'away'
else:
df['home/away'][i] = 'home