Skip to content

Instantly share code, notes, and snippets.

@beneon
Created January 15, 2020 02:08
Show Gist options
  • Save beneon/c88fd2beb513ad211e33d78eea93d5f4 to your computer and use it in GitHub Desktop.
Save beneon/c88fd2beb513ad211e33d78eea93d5f4 to your computer and use it in GitHub Desktop.
数据生成代码
from faker import Faker
import pandas as pd
import os
fk = Faker('zh_CN')
class PtRecord:
def __init__(self,fk):
profile_selector = [
'name',
'sex',
'job',
'residence',
'ssn',
'birthdate',
'blood_group',
]
self.profile = fk.profile(fields=profile_selector)
rst_list = []
for i in range(10):
rst_list.append(PtRecord(fk).profile)
df = pd.DataFrame(rst_list)
output_path = os.path.join('dataset','pt_simple.xlsx')
xlwriter = pd.ExcelWriter(output_path, engine='xlsxwriter')
df.to_excel(xlwriter,'病人数据',index=False)
xlwriter.sheets['病人数据'].set_column('C:F',20)
xlwriter.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment