简体   繁体   English

从名字,姓氏创建电子邮件地址

[英]Create email addresses from first, last name

Goal: input a list of names and output list of corresponding email addresses using the structure 目标:使用该结构输入名称列表并输出相应的电子邮件地址列表

str(first_name) + '.' + str(last_name) + '@gmail.com'

the following function creates a list of randomly generated names... 下面的函数创建一个随机生成的名称列表...

import names

def fill_names(gender = 'female', n = n):
    counter = 0
    name_container = []
    while counter < n:
        name = names.get_full_name(gender = gender)
        name_container.append(name)
        counter += 1
    return name_container

Now that I have the names, I will put them into a dataframe with a bunch of other dataseries that I will omit here... 现在我有了名字,我将它们放入一个数据框中,并在此省略其他一系列数据。

masterDF = pd.DataFrame(columns=['author', 'email')
masterDf.author = fill_names(n = n)

From here I am a bit unsure. 从这里我有点不确定。 Should i use the .split() method to split the first / last name in a for loop? 我应该使用.split()方法在for循环中拆分名字/姓氏吗? Something like (this is more psuedo code)... 有点像(这是更多的伪代码)...

for row in masterDF.author():
    a = masterDF.author.split(' ')
    email = a[0] + '.' + a[1] + '@gmail.com'
    return email

Is there a better way to do this? 有一个更好的方法吗?

You can use str.replace : 您可以使用str.replace

masterDF['email'] = masterDF.author.str.replace('\s+', '.') + '@gmail.com'

Sample: 样品:

masterDF = pd.DataFrame({'author':['name1 surname1','name2 surname2']})

masterDF['email'] = masterDF.author.str.replace('\s+', '.') + '@gmail.com'
print (masterDF)
           author                     email
0  name1 surname1  name1.surname1@gmail.com
1  name2 surname2  name2.surname2@gmail.com

There is also possible use split solution with str.split and then join : 也可以在str.split使用split解决方案,然后join

a = masterDF.author.str.split()
masterDF['email'] = masterDF.str[0] + '.' + masterDF.str[1] + '@gmail.com'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从文件夹内的多个 PDF 文件中提取 email 地址、名字和姓氏 - Extracting email address, first name and last name from multiple PDF files within a folder 在配置文件序列化器中显示名字,姓氏和电子邮件 - show first_name, last_name and email in profile serializer 如何在Python scraper中将名字和姓氏与电子邮件进行匹配 - How to go about matching first and last name to an email in Python scraper python - 创建一个将名字和姓氏列与 IF 语句组合在一起的列 - python - Create a column combining the first and last name columns with IF Statement 通过组合名字和姓氏数组中的值来创建唯一的名称 - Create a unique name by combining the values in the first and last names array 使用 Python 在 excel 中打印唯一名字姓氏电话号码电子邮件和地址详细信息列表 - Printing the list of unique first name last name phone number email and address details in excel using Python 格式化姓氏、名字 - Formatting Last Name, First Name 从电子邮件文本中解析“发件人”地址 - Parsing “From” addresses from email text 删除句点,然后将“@”后的 email 扩展名删除到新列中以提取名字和姓氏信息 - Remove period then email extension after '@' into new column to extract first and last name information 我无法在 django 管理面板中存储名字、姓氏和电子邮件 - I can't store first , last name and email in django admin panel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM