728x90
반응형
Kaggel - Capital bike share demand 과제 中
datetime season holiday workingday weather temp atemp humidity windspeed count
필드 총 10개의 row data를 가지고 있는 train.csv와 test.csv 이 두 파일을 합칠 예정이다.
import csv
import glob
import os
input_path = r'D:\predict' #합칠 파일들이 들어있는 디렉토리 경로
output_file = r'D:\predict\sample.csv' #최종 파일명
file_list = glob.glob(os.path.join(input_path, '*.csv'))
with open(output_file, 'w') as write_file:
for i, file_name in enumerate (file_list):
with open(file_name, 'r') as original_file: # 파일 읽어오기
n = 0
while True:
line = original_file.readline()
#if n == 0: # 모든 csv 파일 릴레이션 삭제
if i != 0 and n == 2: # 첫 번쨰 파일이 아니고, 첫 번쨰 라인인 경우 (릴레이션)
n += 1
continue
if not line:
print(f'File[{i}] Succeed..!')
break
write_file.write(line)
n += 1
print('File Mergin Succeed..!')
결과 train.csv와 test.csv 모두 sample.csv에 합쳐졌다.
그러나 뭐가 문제인건지 train.csv의 마지막 row data와 test.csv의 첫번째 column이 겹쳐지면서 저장된다.
나중에 시간 생기면 다시 찾아봐야겠다.
참고)
728x90
반응형
'[Data Science] > Data Analysis' 카테고리의 다른 글
[Kaggle]bike share demand (1. 첫 발표 후 수정사항) (0) | 2022.07.01 |
---|---|
[Capital bike share demand] Error (0) | 2022.05.11 |
[Bike Sharing Demand]비즈니스 이해 - 자전거 공유 시스템 (0) | 2022.04.27 |
[Kaggle]Capital Bike Sharing (0) | 2022.04.26 |
[Bike Sharing Demand]비즈니스 이해 - Washington D.C. Weather (0) | 2022.04.22 |