func.py
et à l'importer avec Jupyter-notebook.func.py
dans le même dossier que .ipynb
__init __. Py
func.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():
#Liste des chemins de fichiers
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
#rapport lu
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)
#Vérifiez si le bloc de données est vide
if not df.empty:
break
return df
jupyter-notebook
import func
func.read_report_to_dataframe()
Recommended Posts