[Python] 특정 경로에 있는 데이터 한번에 불러오기

데이터 분석에서 자주 활용하는 메소드를 정리합니다.

여러 개의 데이터를 한번에 불러오고 싶을 때

# 라이브러리 임포트
import pandas as pd
import os

# 로데이터 불러오기
data_path = '/content/drive/MyDrive/timeseries/' # 파일 경로
file_list = os.listdir(data_path) # 파일리스트 

# data_path에 존재하는 csv 데이터를 df라는 리스트에 담는다. 
df = []
for file in file_list :
  file_path = os.path.join(data_path, file)
  data = pd.read_csv(file_path)
  df.append(data)

# 파일 갯수 
len(df) 

def join(a, *p)
Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.