-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoloader.py
More file actions
29 lines (28 loc) · 1.05 KB
/
Copy pathautoloader.py
File metadata and controls
29 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import pandas as pd
def create_folder(folder):
if os.path.exists(folder)==0 and folder!="":
try:
os.makedirs(folder) # auto create folder if it doesn't exist
except:
print("\n(꒪Д꒪)ノ\tPATH ERROR -- cannot create folder:", folder)
def load_csv(file_path, header='infer', column_names=None, pickle_path=""):
df = pd.DataFrame()
load_mode = -1
file = os.path.basename(file_path) #"Features_Variant_1.csv"
file_name = os.path.splitext(file)[0] #"Features_Variant_1"
pickle_name = file_name+".pkl"
pickle = os.path.join(pickle_path, pickle_name)
try:
df = pd.read_pickle(pickle)
load_mode = 1
except:
df = pd.read_csv(file_path, header=header, names=column_names)
create_folder(pickle_path)
df.to_pickle(pickle)
load_mode = 0
if load_mode==1:
print("Existing pickle found and loaded: "+pickle)
elif load_mode==0:
print("CSV loaded: "+file_path+", saved as pickle: "+pickle)
return df