Home > Software design >  I'm using Pandas to fix an email list on a column using .replace() but isn't working
I'm using Pandas to fix an email list on a column using .replace() but isn't working

Time:04-09

I'm trying to fix truncated email addresses using Pandas replace() method, I followed several online tutorials, but the results I am getting aren't what I want. this is my first try

filtered_users_emails = pd.read_csv('list_users.csv')
filtered_users_emails_replaced = filtered_users_emails.replace({
                                                              '.c': '.com',
                                                              '.co': '.com'
                                                             })

and the second one using Regex gave me unexpected results


filtered_users_emails = pd.read_csv('list_users.csv')
filtered_users_emails_replaced = filtered_users_emails.replace({
                                                              '.c': '.com',
                                                              '.co': '.com'
                                                             },
                                                             regex=True)

From the above you can see I am trying to replace truncated emails ending in .c and .co, to end as expected in .com

CodePudding user response:

try this one :

filtered_users_emails ['email'] = filtered_users_emails ['email'].str.replace('.co','.com')

CodePudding user response:

this worked for me:

filtered_users_emails['email'] = filtered_users_emails['email'].str.replace('.com*','.c', regex=True) filtered_users_emails['email'] = filtered_users_emails['email'].str.replace('.c','.com', regex=True)
  • Related