Python: サンプルデータの作成1/2

Last Updated on

サンプルデータの作成1

サンプルデータの作成2

 

架空のサンプルデータを簡単に作成できます。次の文書にしたがって、Azure Notebooksで作成しました。

 

Dataset unavailable? No problem!

 

Python Faker Library

 

I.英語のサンプルデータを作成

 

II.日本語のサンプルデータを作成

 

 

III.スクリプト

 

!pip install Faker
from faker import Faker
import pandas as pd
import numpy as np
fake = Faker()
fake.seed(4321)
ID=[]
name=[]
phone=[]
age=[]
gender=[]
address=[]
checkin=[]
checkout=[]
for _ in range(100):
 phone.append(fake.phone_number())
 address.append(fake.address())
 name.append(fake.name())
ID=pd.Series(range(1,101))
age=np.random.randint(8, high=80, size=100)
gender=np.random.choice([0, 1], size=100, p=[.6, .4])
df=pd.DataFrame({'ID':ID,'name':name,'phone':phone,'age':age,'gender':gender,'address':address})
print(df.head(10))
# Japanese
fake = Faker('ja_JP')
fake.seed(4321)
ID=[]
name=[]
phone=[]
age=[]
gender=[]
address=[]
checkin=[]
checkout=[]
for _ in range(100):
 phone.append(fake.phone_number())
 address.append(fake.address())
 name.append(fake.name())
ID=pd.Series(range(1,101))
age=np.random.randint(8, high=80, size=100)
gender=np.random.choice([0, 1], size=100, p=[.6, .4])
df=pd.DataFrame({'ID':ID,'name':name,'phone':phone,'age':age,'gender':gender,'address':address})
print(df.head(10))

 

Please follow and like us:

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.