배드민턴 예선경기 일정을 VS Code AI 에서 xlsx 파일 생성하기.

이 노트북 파일은 배드민턴 경기 일정 데이터를 분석하고, 드림클럽이 참여하는 경기만 추려서 엑셀 파일로 저장하는 과정을 담고 있습니다. 초보자를 위해 각 단계별로 쉽게 설명드리면 다음과 같습니다:

  1. 필요한 라이브러리 불러오기
  • pandas, numpy, re 등 데이터를 다루기 위한 파이썬 라이브러리를 불러옵니다.
  1. 텍스트 파일에서 데이터 읽기
  • 경기 일정이 담긴 텍스트 파일(0913.txt, 0914.txt)을 한 줄씩 읽어옵니다.
  1. 경기 정보 추출
  • 각 줄을 분석해서 코트, 경기 시간, 경기종목, 클럽 이름, 선수 이름 등 필요한 정보를 뽑아냅니다.
  • 한 경기의 정보가 모두 모이면 리스트에 저장합니다.
  1. 드림클럽 경기만 추리기
  • 전체 경기 중에서 드림클럽이 참여한 경기만 골라냅니다.
  • 만약 드림클럽이 상대팀으로 나온 경우, 정보의 위치를 바꿔서 드림클럽이 항상 ‘클럽’ 칸에 오도록 정리합니다.
  1. 데이터 정리 및 가공
  • 경기 시간 순서대로 정렬합니다.
  • 선수 이름은 3글자마다 쉼표로 구분해서 보기 쉽게 만듭니다.
  • 각 경기마다 번호를 붙입니다.
  • 원하는 순서대로 열(컬럼)을 재배치합니다.
  1. 엑셀 파일로 저장
  • 정리된 데이터를 엑셀 파일로 저장합니다. 예를 들어 토예선.xlsx, 일예선.xlsx 등으로 저장됩니다.

이 노트북을 실행하면, 드림클럽이 참여하는 경기만 시간순으로 정리된 엑셀 파일을 자동으로 만들 수 있습니다.
초보자도 각 셀을 순서대로 실행하면 결과를 쉽게 얻을 수 있습니다.
궁금한 부분이나 더 알고 싶은 내용이 있으면 언제든 질문해 주세요!

Excel 파일로 저장

텍스트 파일에서 데이터 읽기

with open(‘0914.txt’, ‘r’, encoding=’utf-8′) as file:
lines = file.readlines()

경기 데이터를 저장할 리스트

matches = []

데이터 파싱

current_match = {}
for line in lines:
line = line.strip()
if not line:
continue

if '코트 - ' in line and '경기' in line:
    if current_match:
        matches.append(current_match.copy())
    current_match = {}
    court_info = line.split(' - ')
    current_match['코트'] = court_info[0]

elif ':' in line:
    current_match['시간'] = line

elif '개인전' in line:
    current_match['경기종목'] = line

elif any(club in line for club in ['드림클럽', '함마루클럽', '시화클럽', '목감클럽']):
    club_name = line.strip()
    if '클럽' not in current_match:
        current_match['클럽'] = club_name
        current_match['선수'] = ''
    else:
        current_match['상대클럽'] = club_name
        current_match['상대선수'] = ''

elif line != '경기예정' and not line.startswith('코트'):
    if '선수' not in current_match or not current_match['선수']:
        current_match['선수'] = line
    else:
        current_match['상대선수'] = line

마지막 경기 추가

if current_match:
matches.append(current_match)

DataFrame 생성

df = pd.DataFrame(matches)

드림클럽 경기만 필터링하고 정보 재정렬

dream_club_matches = df[df[‘클럽’].str.contains(‘드림클럽’) | df[‘상대클럽’].str.contains(‘드림클럽’)].copy()

드림클럽이 상대클럽인 경우 정보 교환

mask = dream_club_matches[‘상대클럽’].str.contains(‘드림클럽’, na=False)
dream_club_matches.loc[mask, [‘클럽’, ‘선수’, ‘상대클럽’, ‘상대선수’]] = \
dream_club_matches.loc[mask, [‘상대클럽’, ‘상대선수’, ‘클럽’, ‘선수’]].values

시간순으로 정렬

dream_club_matches = dream_club_matches.sort_values(‘시간’)

선수 이름 분리 (공백을 콤마로 변경)

dream_club_matches[‘선수’] = dream_club_matches[‘선수’].str.replace(‘ ‘, ‘, ‘)
dream_club_matches[‘상대선수’] = dream_club_matches[‘상대선수’].str.replace(‘ ‘, ‘, ‘)

번호 추가

dream_club_matches.insert(0, ‘번호’, range(1, len(dream_club_matches) + 1))

컬럼 순서 재정렬

columns_order = [‘번호’, ‘시간’, ‘경기종목’, ‘코트’, ‘클럽’, ‘선수’, ‘상대클럽’, ‘상대선수’]
dream_club_matches = dream_club_matches[columns_order]

결과 출력

display(dream_club_matches)

dream_club_matches.to_excel(‘드림예선경기.xlsx’, index=False)
print(‘엑셀 파일이 생성되었습니다: 드림예선경기.xlsx’)

Excel 파일로 저장

dream_club_matches.to_excel(‘드림예선경기.xlsx’, index=False)
print(‘엑셀 파일이 생성되었습니다: 드림예선경기.xlsx’)

import pandas as pd
import re

def split_name_by_three(name):
# 한글 3글자마다 쉼표 추가
return ‘, ‘.join([name[i:i+3] for i in range(0, len(name), 3)])

with open(‘0913.txt’, ‘r’, encoding=’utf-8′) as file:
lines = file.readlines()

matches = []
current_match = {}
for line in lines:
line = line.strip()
if not line:
continue
# 코트 – 몇경기
if re.match(r’\d+코트 – \d+경기’, line):
if current_match:
matches.append(current_match.copy())
current_match = {}
current_match[‘코트 – 몇경기’] = line
elif ‘:’ in line:
current_match[‘시간’] = line
elif ‘개인전’ in line:
current_match[‘경기종목’] = line
elif any(club in line for club in [‘드림클럽’, ‘함마루클럽’, ‘시화클럽’, ‘목감클럽’]):
club_name = line.strip()
if ‘클럽’ not in current_match:
current_match[‘클럽’] = club_name
current_match[‘선수’] = ”
else:
current_match[‘상대클럽’] = club_name
current_match[‘상대선수’] = ”
elif line != ‘경기예정’ and not line.startswith(‘코트’):
if ‘선수’ not in current_match or not current_match[‘선수’]:
current_match[‘선수’] = line
else:
current_match[‘상대선수’] = line
if current_match:
matches.append(current_match)
df = pd.DataFrame(matches)

드림클럽 경기만 필터링

dream_club_matches = df[df[‘클럽’].str.contains(‘드림클럽’) | df[‘상대클럽’].str.contains(‘드림클럽’)].copy()

드림클럽이 상대클럽인 경우 정보 교환

mask = dream_club_matches[‘상대클럽’].str.contains(‘드림클럽’, na=False)
dream_club_matches.loc[mask, [‘클럽’, ‘선수’, ‘상대클럽’, ‘상대선수’]] = \
dream_club_matches.loc[mask, [‘상대클럽’, ‘상대선수’, ‘클럽’, ‘선수’]].values

시간순으로 정렬

dream_club_matches = dream_club_matches.sort_values(‘시간’)

선수 이름 3글자마다 쉼표

dream_club_matches[‘선수’] = dream_club_matches[‘선수’].apply(split_name_by_three)
dream_club_matches[‘상대선수’] = dream_club_matches[‘상대선수’].apply(split_name_by_three)

번호 추가

dream_club_matches.insert(0, ‘번호’, range(1, len(dream_club_matches) + 1))

컬럼 순서 및 이름 맞추기

columns_order = [‘번호’, ‘시간’, ‘경기종목’, ‘코트 – 몇경기’, ‘클럽’, ‘선수’, ‘상대클럽’, ‘상대선수’]
dream_club_matches = dream_club_matches[columns_order]
dream_club_matches.to_excel(‘토예선.xlsx’, index=False) print(‘엑셀 파일이 생성되었습니다: 토예선.xlsx’)

import pandas as pd
import re

def split_name_by_three(name):
return ‘, ‘.join([name[i:i+3] for i in range(0, len(name), 3)])

with open(‘0914.txt’, ‘r’, encoding=’utf-8′) as file:
lines = file.readlines()

matches = []
current_match = {}
for line in lines:
line = line.strip()
if not line:
continue
if re.match(r’\d+코트 – \d+경기’, line):
if current_match:
matches.append(current_match.copy())
current_match = {}
current_match[‘코트 – 몇경기’] = line
elif ‘:’ in line:
current_match[‘시간’] = line
elif ‘개인전’ in line:
current_match[‘경기종목’] = line
elif any(club in line for club in [‘드림클럽’, ‘함마루클럽’, ‘시화클럽’, ‘목감클럽’]):
club_name = line.strip()
if ‘클럽’ not in current_match:
current_match[‘클럽’] = club_name
current_match[‘선수’] = ”
else:
current_match[‘상대클럽’] = club_name
current_match[‘상대선수’] = ”
elif line != ‘경기예정’ and not line.startswith(‘코트’):
if ‘선수’ not in current_match or not current_match[‘선수’]:
current_match[‘선수’] = line
else:
current_match[‘상대선수’] = line
if current_match:
matches.append(current_match)
df = pd.DataFrame(matches)
dream_club_matches = df[df[‘클럽’].str.contains(‘드림클럽’) | df[‘상대클럽’].str.contains(‘드림클럽’)].copy()
mask = dream_club_matches[‘상대클럽’].str.contains(‘드림클럽’, na=False)
dream_club_matches.loc[mask, [‘클럽’, ‘선수’, ‘상대클럽’, ‘상대선수’]] = \
dream_club_matches.loc[mask, [‘상대클럽’, ‘상대선수’, ‘클럽’, ‘선수’]].values
dream_club_matches = dream_club_matches.sort_values(‘시간’)
dream_club_matches[‘선수’] = dream_club_matches[‘선수’].apply(split_name_by_three)
dream_club_matches[‘상대선수’] = dream_club_matches[‘상대선수’].apply(split_name_by_three)
dream_club_matches.insert(0, ‘번호’, range(1, len(dream_club_matches) + 1))
columns_order = [‘번호’, ‘시간’, ‘경기종목’, ‘코트 – 몇경기’, ‘클럽’, ‘선수’, ‘상대클럽’, ‘상대선수’]
dream_club_matches = dream_club_matches[columns_order]
dream_club_matches.to_excel(‘일예선.xlsx’, index=False) print(‘엑셀 파일이 생성되었습니다: 일예선.xlsx’)

드림클럽 경기 일정 분석 노트북 안내 (초보자용)

이 노트북은 배드민턴 대회에서 드림클럽이 참가하는 경기 일정을 정리하고, 엑셀 파일로 저장하는 과정을 담고 있습니다. 초보자도 쉽게 따라할 수 있도록 각 단계별로 설명합니다.

  1. 필요한 라이브러리 불러오기
  • 데이터 분석에 필요한 파이썬 라이브러리(pandas, numpy 등)를 불러옵니다.
  1. 텍스트 파일에서 데이터 읽기
  • 경기 일정이 담긴 텍스트 파일(예: 0913.txt, 0914.txt)을 한 줄씩 읽어옵니다.
  1. 경기 정보 추출
  • 각 줄을 분석해서 코트, 시간, 경기종목, 클럽, 선수 등 필요한 정보를 뽑아냅니다.
  • 한 경기의 정보가 모두 모이면 리스트에 저장합니다.
  1. 드림클럽 경기만 추리기
  • 전체 경기 중에서 드림클럽이 참여한 경기만 골라냅니다.
  • 드림클럽이 상대팀으로 나온 경우, 정보의 위치를 바꿔서 드림클럽이 항상 ‘클럽’ 칸에 오도록 정리합니다.
  1. 데이터 정리 및 가공
  • 경기 시간 순서대로 정렬합니다.
  • 선수 이름은 보기 쉽게 쉼표로 구분합니다.
  • 각 경기마다 번호를 붙입니다.
  • 원하는 순서대로 열(컬럼)을 재배치합니다.
  1. 엑셀 파일로 저장
  • 정리된 데이터를 엑셀 파일로 저장합니다. (예: 토예선.xlsx, 일예선.xlsx 등)

이 노트북을 셀 순서대로 실행하면 드림클럽이 참여하는 경기만 시간순으로 정리된 엑셀 파일을 자동으로 만들 수 있습니다.

궁금한 점이 있으면 언제든 질문해 주세요!


게시됨

카테고리

, ,

작성자

태그:

댓글

“배드민턴 예선경기 일정을 VS Code AI 에서 xlsx 파일 생성하기.”에 하나의 반응이 있습니다

  1. fixian Avatar

    대회준비 – 필수사항

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다