func.py
and import it with Jupyter-notebook.func.py
to the same folder as .ipynb
__init__.py
filefunc.py
import pandas as pd
import os,glob
from datetime import datetime as dt
from multiprocessing import Pool
FOLDER_PATH = r'folder_path\\'
FILE_TYPE = r'*.csv'
FILE_FORMAT = 'Report_%Y%m%d.csv'
def read_report_to_dataframe():
#List file paths
csv_pathlist = glob.glob(FOLDER_PATH + FILE_TYPE)
with Pool(os.cpu_count()) as p:
df = pd.concat(p.map(read_report, csv_pathlist))
return df
#report read
def read_report(csv_path):
separator_list = [';',',']
for sep in separator_list:
df = pd.read_csv(filepath_or_buffer=csv_path,
engine='python',
parse_dates=[0],
index_col=[0],
skiprows=[1],
nrows=96,
sep=sep)
#Check if the data frame is empty
if not df.empty:
break
return df
jupyter-notebook
import func
func.read_report_to_dataframe()
Recommended Posts