-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_data.py
More file actions
23 lines (18 loc) · 751 Bytes
/
load_data.py
File metadata and controls
23 lines (18 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Step 1: Downloading zip file
import os
import pandas as pd
def download_and_load_data():
# Download only if not already present
if not os.path.exists('LD2011_2014.txt'):
import urllib.request, zipfile
print("Downloading...")
url = 'https://archive.ics.uci.edu/static/public/321/electricityloaddiagrams20112014.zip'
urllib.request.urlretrieve(url, 'LD2011_2014.txt.zip')
print("Unzipping...")
with zipfile.ZipFile('LD2011_2014.txt.zip', 'r') as zip_ref:
zip_ref.extractall()
# Step 2: Load dataset
df = pd.read_csv('LD2011_2014.txt', sep=';', index_col=0, parse_dates=True, decimal=',')
# Optional: convert to hourly
df = df.resample('1h').mean()
return df