Notice
Recent Posts
Recent Comments
Link
아미(아름다운미소)
pandas 주차차이 구하기 본문
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)
'랭귀지 > pandas' 카테고리의 다른 글
Pandas에서 DataFrame의 특정 컬럼 특정값 (0) | 2024.07.31 |
---|---|
pandas 컬럼리스트 확인 (0) | 2024.07.25 |
pandas 전주차 구하기 (0) | 2024.07.23 |
pandas 컬럼이름을 마지막으로이동 (0) | 2024.07.22 |
pandas 컬럼값변경 (0) | 2024.07.20 |
Comments