func.py
zu speichern und mit Jupyter-Notebook zu importieren.func.py
in den gleichen Ordner wie .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():
#Dateipfade auflisten
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
#Bericht gelesen
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)
#Überprüfen Sie, ob der Datenrahmen leer ist
if not df.empty:
break
return df
jupyter-notebook
import func
func.read_report_to_dataframe()
Recommended Posts