How to create a CSV dummy file containing Japanese using Faker

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

environment

Referenced site

What you need for advance preparation

Install Faker

/path/to/hoge


pip install fake-factory

Faker does not support Japanese

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.

Sample program to create CSV 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)

How to create dummy data that seems to be used often

I can't say anything because I've only touched it a little ...

date

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")

Number range

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

email

fake.email()
# [email protected]

Please refer to Faker for details. Please use it for DB sample data and file IO test.

Recommended Posts

How to create a CSV dummy file containing Japanese using Faker
How to create a config file
How to paste a CSV file into an Excel file using Pandas
How to read a CSV file with Python 2/3
How to create a JSON file in Python
Create a dummy data file
Python script to create a JSON file from a CSV file
How to create a Conda package
How to create a virtual bridge
How to create a Dockerfile (basic)
[Python] How to store a csv file as one-dimensional array data
[Python] How to convert db file to csv
How to create a clone from Github
How to create a git clone folder
How to install a package using a repository
[Python] How to scrape a local html file and output it as CSV using Beautiful Soup
How to create a repository from media
Script to create a Mac dictionary file
How to put a line number at the beginning of a CSV file
[Python] How to read a csv file (read_csv method of pandas module)
How to create sample CSV data with hypothesis
How to disguise a ZIP file as a PNG file
How to create a Python virtual environment (venv)
How to code a drone using image recognition
How to create a function object from a string
I tried reading a CSV file using Python
How to create a shortcut command for LINUX
[Note] How to create a Ruby development environment
How to create a Kivy 1-line input box
How to create a multi-platform app with kivy
How to create a Rest Api in Django
Create a MIDI file in Python using pretty_midi
How to upload to a shared drive using pydrive
How to uninstall a module installed using setup.py
How to read a file in a different directory
[Note] How to create a Mac development environment
Aggregate steps by day from iPhone healthcare data to create a CSV file
Read the Python-Markdown source: How to create a parser
How to write a GUI using the maya command
How to set up a Python environment using pyenv
How to create a submenu with the [Blender] plugin
Create dummy data using Python's NumPy and Faker packages
Every time I try to read a csv file using pandas, I get a numpy error.
What you can understand because you are a beginner How to create a file (first post)
How to hold a hands-on seminar using Jupyter using docker
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
How to unit test a function containing the current time using freezegun in python
How to convert JSON file to CSV file with Python Pandas
How to turn a .py file into an .exe file
How to make a Python package using VS Code
How to convert a mel spectrogram back to a wav file
How to create a local repository for Linux OS
How to save a table scraped by python to csv
How to create a simple TCP server / client script
How to convert Json file to CSV format or EXCEL format
[Python] How to create a 2D histogram with Matplotlib
How to execute a command using subprocess in Python
How to create a radial profile from astronomical images (Chandra, XMM etc.) using python
How to read csv containing only integers in Python
How to use NUITKA-Utilities hinted-compilation to easily create an executable file from a Python script
How to create a kubernetes pod from python code