랭귀지/pandas

pandas 주차차이 구하기

유키공 2024. 7. 23. 13:30
import pandas as pd

# 시작 주차와 종료 주차 설정
start_week_str = '202352'
end_week_str = '202405'

# 연도와 주차 분리
start_year = int(start_week_str[:4])
start_week = int(start_week_str[4:])
end_year = int(end_week_str[:4])
end_week = int(end_week_str[4:])

# 주차 리스트 초기화
weeks = []

# 주차 계산
current_year = start_year
current_week = start_week

while (current_year < end_year) or (current_year == end_year and current_week <= end_week):
    weeks.append(f"{current_year}{str(current_week).zfill(2)}")  # 주차를 문자열 형태로 저장
    current_week += 1
    if current_week > 52:  # 주차가 52를 넘으면 연도를 증가시키고 주차를 1로 초기화
        current_week = 1
        current_year += 1

# 결과 출력
print(weeks)