I have a large pandas dataframe of email address and wanted to replace all the .edu emails with "Edu". I came up with an highly inefficient way of doing it but there has to be a better way of doing it. This is how I do it:
import pandas as pd
import re
inp = [{'c1':10, 'c2':'gedua.com'}, {'c1':11,'c2':'wewewe.Edu'}, {'c1':12,'c2':'wewewe.edu.ney'}]
dfn = pd.DataFrame(inp)
for index, row in dfn.iterrows():
try:
if len(re.search('\.edu', row['c2']).group(0)) > 1:
dfn.c2[index] = 'Edu'
print('Education')
except:
continue
.Edu? Or do you also want to change all variations of .edu regardless of capitalization?