When creating CSV dummy data, there are many dummy creation sites in the street. In most cases, Japanese is not supported.
Therefore, a memo when creating CSV dummy data in Japanese using Python's Faker
/path/to/hoge
pip install fake-factory
Quoted from joke2k / faker
You can check available Faker locales in the source code, under the providers package. The localization of Faker is an ongoing process, for which we need your help. Please don't hesitate to create a localized provider for your own locale and submit a Pull Request (PR).
Included localized providers:
bg_BG cs_CZ de_DE dk_DK . .
There is currently no ja_JP. So create your own provider and create dummy data including Japanese.
fake.add_provider()Use to create your own provider.
#### **`ja_dummy.py`**
```python
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from faker import Factory
from faker.providers import BaseProvider
import csv
import random
class MyStatusProvider(BaseProvider):
def state(self):
return random.choice(['State 1', 'State 2', 'State 3'])
def name(self):
return random.choice(['Tanaka', 'Suzuki', 'Yamazaki'])
def phone_number(self):
return random.choice(['080-1111-2222', '090-1234-5678', '070-1234-5678'])
fake = Factory.create()
fake.add_provider(MyStatusProvider)
with open("dummy_data.csv", "w+") as f:
csv_writer = csv.writer(f)
for i in range(5):
l = [fake.md5(), fake.random_number(1), fake.date(pattern="%Y-%m-%d %H:%M:%S"), fake.random_int(min=0, max=1), fake.boolean(), fake.state(), fake.name(), fake.phone_number() ]
csv_writer.writerow(l)
`for i in range ({number})`
part specifies the number of CSV creation linesI can't say anything because I've only touched it a little ...
You can make it any date type by changing the pattern part
fake.date(pattern="%Y-%m-%d %H:%M:%S")
fake.date(pattern="%Y year%m month%d day%H o'clock%M minutes%S seconds")
If you want to randomly create data with numbers from 0 to 9
fake.random_int(min=0, max=9)
md5
fake.md5()
# 292bfff99620e2ae2f3b2f5b9fab4232
# 739169affdb932770deed3ff5f29f7b9
True or False
fake.boolean()
# False
# True
fake.email()
# [email protected]
Please refer to Faker for details. Please use it for DB sample data and file IO test.
Recommended Posts