import random
from openpyxl import workbook
from faker import Faker
wb = workbook.Workbook()
sheet = wb.worksheets[0]
sheet.title = 'pd练习'
li = ['序号', '姓名', '年龄', '性别', '健康程度', '国家']
di = {'中国': 'zh_CN', '美国': 'en_US', '法国': 'fr_FR', '日本': 'ja_JP'}
with open('new_message.xlsx', mode='w', encoding='utf-8') as f:
for num, item in enumerate(li, 1):
sheet.cell(1, num).value = item
for num, i in enumerate(range(2, 502), 1):
country = random.choice(['中国', '美国', '法国', '日本'])
gender = random.choice(['男', '女'])
fk = Faker(locale=di[country])
sheet.cell(i, 1).value = num
sheet.cell(i, 2).value = fk.name_male() if gender == '男' else fk.name_female()
sheet.cell(i, 3).value = random.randint(14, 66)
sheet.cell(i, 4).value = gender
sheet.cell(i, 5).value = round(random.random(), 2)
sheet.cell(i, 6).value = country
wb.save('new_message.xlsx')