본문 바로가기
코딩

가짜 이름, 주소 데이터를 생성하는 파이썬 코드를 만들어보자.(Faker 라이브러리)

by 노마드랩스 2023. 2. 5.
728x90
반응형

Faker 라이브러리를 활용하여 가짜데이터 만들어보는 코드를 작성해보겠습니다.

 

이 코드는 Faker 라이브러리를 사용하여 가짜 이름과 주소를 생성하고 튜플 목록에 저장합니다. 

그런 다음 목록은 더 쉬운 조작 및 분석을 위해 Pandas DataFrame으로 변환됩니다. 

head() 함수는 DataFrame의 처음 5개 행을 표시하는 데 사용되므로 생성된 가짜 데이터가 어떻게 보이는지 확인할 수 있습니다.

from faker import Faker
import pandas as pd

# Create an instance of the Faker class
fake = Faker()

# Generate a list of fake names and addresses
fake_data = []
for i in range(100):
    name = fake.name()
    address = fake.address()
    fake_data.append((name, address))

# Convert the list of tuples to a Pandas DataFrame
df = pd.DataFrame(fake_data, columns=['Name', 'Address'])

# Print the first 5 rows of the DataFrame
print(df.head())

728x90
반응형

댓글