-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathelect_preprocessing.py
More file actions
27 lines (24 loc) · 920 Bytes
/
elect_preprocessing.py
File metadata and controls
27 lines (24 loc) · 920 Bytes
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
from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile
import os
import pandas as pd
if __name__ == '__main__':
save_name = 'elect'
name = 'LD2011_2014.txt'
save_path = os.path.join('data_raw', save_name)
if not os.path.exists(save_path):
os.makedirs(save_path)
csv_path = os.path.join(save_path, name)
if not os.path.exists(csv_path):
zipurl = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00321/LD2011_2014.txt.zip'
print('Start download')
with urlopen(zipurl) as zipresp:
print('Start unzip')
with ZipFile(BytesIO(zipresp.read())) as zfile:
zfile.extractall(save_path)
print('Treating and saving')
data_frame = pd.read_csv(csv_path, sep=";", index_col=0, parse_dates=True, decimal=',')
#data_frame = data_frame.resample('1H',label = 'left',closed = 'right').sum()
data_frame.fillna(0, inplace=True)
data_frame.to_csv(csv_path)