I have a dataset , in which one of the columns is Degree, from that column i want to looking for a particular keyword and for that keyword i want to add a short form in a list. My initial code works fine for me:
c = []
for words in df['Degree'].values:
if "(m.tech)" in words.lower():
c.append("M.Tech")
elif "m.tech" in words.lower():
c.append("M.Tech")
elif "(m.sc)" in words.lower():
c.append("M.Sc")
elif "m.sc" in words.lower():
c.append("M.Sc")
elif "post" in words.lower():
c.append("PG")
elif "(b.tech)" in words.lower():
c.append("B.Tech")
elif "(b.e)" in words.lower():
c.append("B.Tech")
elif "b.tech" in words.lower():
c.append("B.Tech")
elif "b.e" in words.lower():
c.append("B.Tech")
else:
c.append(np.nan)
But i want to make it small using "OR" . so i wrote:
d = []
for words in df['Degree'].values:
if "(m.tech)" or "m.tech" in words.lower():
d.append("M.tech")
elif "(m.sc)" or "m.sc" in words.lower():
d.append("M.Sc")
elif "(b.tech)" or "b.tech" or "b.e" or "(b.e)" in words.lower():
d.append("B.Tech")
elif "post" or "pg" in words.lower():
d.append("PG")
else:
d.append(np.nan)
In this piece of code, what i get is only "M.Tech" values , even if if has nan value.
Any help ?