1 분 소요

오늘은 Steam 게임 데이터셋을 영어와 한국어를 지원하는 게임만 포함하도록 필터링하는 작업을 했습니다. Python과 pandas를 사용하여 이를 어떻게 달성했는지 단계별로 설명하겠습니다.

1단계: 데이터셋 로드

먼저, JSON 파일에서 Python 딕셔너리로 데이터를 로드했습니다.

import os
import json

dataset = {}
if os.path.exists('games.json'):
    with open('games.json', 'r', encoding='utf-8') as fin:
        text = fin.read()
        if len(text) > 0:
            dataset = json.loads(text)

2단계: DataFrame으로 변환

그 다음, 딕셔너리를 pandas DataFrame으로 변환하여 더 쉽게 조작할 수 있도록 했습니다.

import pandas as pd

df = pd.DataFrame(dataset).T

3단계: DataFrame 필터링

이제 DataFrame을 필터링하여 영어와 한국어를 모두 지원하는 게임만 포함하도록 했습니다.

df_filtered = df[df["supported_languages"].apply(lambda x: "English" in x and "Korean" in x)]

4단계: 필터링된 데이터 저장

마지막으로, 필터링된 DataFrame을 CSV 파일로 저장했습니다.

df_filtered.to_csv('games_support_KoreanandEnglish.csv', index=False)

전체 코드

참고용으로 전체 코드를 여기에 포함했습니다:

import os
import json
import pandas as pd

# 데이터셋 로드
dataset = {}
if os.path.exists('games.json'):
    with open('games.json', 'r', encoding='utf-8') as fin:
        text = fin.read()
        if len(text) > 0:
            dataset = json.loads(text)

# DataFrame으로 변환
df = pd.DataFrame(dataset).T

# DataFrame 필터링
df_filtered = df[df["supported_languages"].apply(lambda x: "English" in x and "Korean" in x)]

# 필터링된 데이터 저장
df_filtered.to_csv('games_support_KoreanandEnglish.csv', index=False)

결론

이 단계를 따라 Steam 게임 데이터셋을 영어와 한국어를 지원하는 게임만 포함하도록 필터링할 수 있었습니다. 이 과정은 데이터를 로드하고, DataFrame으로 변환하고, 필터를 적용하고, 결과를 저장하는 단계를 포함합니다. 이 방법은 다른 필터링 기준에도 적용할 수 있습니다.

태그: ,

카테고리:

업데이트:

댓글남기기