pip install -r requirements.txt
Collecting matplotlib==3.2.1
Downloading matplotlib-3.2.1-cp37-cp37m-manylinux1_x86_64.whl (12.4 MB)
|████████████████████████████████| 12.4 MB 5.8 MB/s
Collecting numpy==1.18.5
Downloading numpy-1.18.5-cp37-cp37m-manylinux1_x86_64.whl (20.1 MB)
|████████████████████████████████| 20.1 MB 24.4 MB/s
Collecting pandas==1.0.4
Downloading pandas-1.0.4-cp37-cp37m-manylinux1_x86_64.whl (10.1 MB)
|████████████████████████████████| 10.1 MB 18.3 MB/s
Requirement already satisfied: cycler>=0.10 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from matplotlib==3.2.1->-r requirements.txt (line 7)) (0.10.0)
Requirement already satisfied: python-dateutil>=2.1 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from matplotlib==3.2.1->-r requirements.txt (line 7)) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from matplotlib==3.2.1->-r requirements.txt (line 7)) (1.3.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from matplotlib==3.2.1->-r requirements.txt (line 7)) (2.4.7)
Requirement already satisfied: pytz>=2017.2 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas==1.0.4->-r requirements.txt (line 9)) (2021.1)
Requirement already satisfied: six in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from cycler>=0.10->matplotlib==3.2.1->-r requirements.txt (line 7)) (1.16.0)
Installing collected packages: numpy, pandas, matplotlib
Attempting uninstall: numpy
Found existing installation: numpy 1.19.5
Uninstalling numpy-1.19.5:
ERROR: Could not install packages due to an OSError: [Errno 30] Read-only file system: '/shared-libs/python3.7/py/bin/f2py'
WARNING: You are using pip version 21.1.3; however, version 21.2.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Note: you may need to restart the kernel to use updated packages.
#Import libraries
import pandas as pd #https://pandas.pydata.org/
import matplotlib.pyplot as plt #https://matplotlib.org/
import matplotlib.dates as mdates #https://matplotlib.org/
import numpy as np #http://www.numpy.org/
#from datetime import date #https://docs.python.org/3/library/datetime.html
#Read csv file using pandas
#https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html
ElectricityConsumption = pd.read_csv("cons.csv",dayfirst=True,sep=";",
header=0,decimal=b",",index_col=0,
parse_dates=True)
ElectricityConsumption.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 4631 entries, 2017-12-20 00:00:00 to 2018-06-30 23:00:00
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 LRE000_2003210 4631 non-null float64
dtypes: float64(1)
memory usage: 72.4 KB
#Checking the table
#ElectricityConsumption #Full table
ElectricityConsumption.head() #Just a sample from "head()"
#Creating a basic plot using matplotlib
plt.plot(ElectricityConsumption)
#Improving visualization
#####
#https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot
#####
#plot size
plt.figure(figsize=(16,6))
#plot, defining color, marker and line style
plt.plot(ElectricityConsumption,color='black', marker='.',linestyle='none')
plt.title("Electricity consumption from 20.12.2017 - 30.6.2018")
plt.ylabel("Energy in [kWh]") #y-axis label
plt.grid(True) #grid
plt.show() #show plot
#Information about specific periods
ElectricityConsumption['2018-3'].info() #one month
#ElectricityConsumption['2018-1':'2018-3'].info() #ranges months
#ElectricityConsumption['2018-1-1':'2018-1-14'].info() #ranges days
#ElectricityConsumption['2018-1-14 02:00:00':'2018-1-17 04:00:00'].info() #ranges hours
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 743 entries, 2018-03-01 00:00:00 to 2018-03-31 23:00:00
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 LRE000_2003210 743 non-null float64
dtypes: float64(1)
memory usage: 11.6 KB
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
#Six months
plt.figure(figsize=(16,6))
plt.plot(ElectricityConsumption['2018-1':'2018-6'],color='green', marker='.',linestyle='')
plt.title("Electricity consumption from January to June, 2018")
plt.ylabel("Energy in [kWh]")
plt.grid(True)
plt.show()
#One month
plt.figure(figsize=(16,6))
plt.plot(ElectricityConsumption['2018-2'],color='black', marker='x',linestyle='')
plt.title("Electricity consumption in Feb, 2018")
plt.ylabel("Energy in [kWh]")
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:3: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
This is separate from the ipykernel package so we can avoid doing imports until
#One day
fig, ax = plt.subplots(1,figsize=(16,6))
plt.plot(ElectricityConsumption['2018-3-31'],color='black', marker='o',linestyle='--')
plt.title("Electricity consumption in march 31, 2018")
plt.ylabel("Energy in [kWh]")
plt.grid(True)
plt.tight_layout()
#change x axis
xfmt = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(xfmt)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:3: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
This is separate from the ipykernel package so we can avoid doing imports until
#Plot two days
#Day1
day1 = '2018-04-29'
#Day2
day2 = '2018-05-01'
#Difference
delta = ElectricityConsumption[day2:].index[0].date() - ElectricityConsumption[day1:].index[0].date()
#
fig, ax = plt.subplots(1,figsize=(16,6))
#
plt.plot(ElectricityConsumption[day1:day1], label=day1, color='black',
marker='o',linestyle='--')
plt.plot(ElectricityConsumption[day2:day2].index - pd.offsets.Day(delta.days),
ElectricityConsumption[day2:day2].values, label=day2, color='blue', marker='x',linestyle='-')
plt.legend()
plt.ylim([0, 6])
plt.title("Electricity consumption")
plt.ylabel("Energy in [kWh]")
plt.grid(True)
plt.tight_layout()
#change x axis
xfmt = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(xfmt)
#
plt.show()
#Uploading the temperature from this day in Lappeenranta
#http://en.ilmatieteenlaitos.fi/download-observations#!/
#Note parse_dates to combine the first columns, also note that the separator from
#decimal is "." and data separator is ","
Temperature = pd.read_csv("data-test.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,5])
Temperature.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 145 entries, 2013-09-07 00:00:00 to 2013-09-08 00:00:00
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Air temperature (degC) 145 non-null float64
dtypes: float64(1)
memory usage: 2.3 KB
#plotting
plt.figure(figsize=(16,6))
plt.plot(Temperature,color='blue', marker='x',linestyle=':')
plt.title("Air temperature in sep 7, 2013, at Lappeenranta airport station")
plt.ylabel("Temperature in [°C]")
plt.grid(True)
plt.show()
Temperature2 = pd.read_csv("temp-20180429-LPR-airport.csv",dayfirst=True,sep=",",
header=0,decimal=b".",index_col=0,
parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,5])
Temperature2.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 25 entries, 2018-04-29 00:00:00 to 2018-04-30 00:00:00
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Air temperature (degC) 25 non-null float64
dtypes: float64(1)
memory usage: 400.0 bytes
#plotting
plt.figure(figsize=(16,6))
plt.plot(Temperature2['2018-4-29'],color='blue', marker='x',linestyle=':')
plt.plot(Temperature2['2018-4-29'] > 11,color='black', marker='o',linestyle='')
plt.title("Air temperature in April 29, 2018, at Lappeenranta airport station")
plt.ylabel("Temperature in [°C]")
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:3: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
This is separate from the ipykernel package so we can avoid doing imports until
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:4: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
after removing the cwd from sys.path.
#subplot function
#https://matplotlib.org/2.0.1/examples/api/two_scales.html
####
fig, ax1 = plt.subplots(figsize=(16,6))
#left axis
ax1.set_ylabel("Energy in [kWh]", color='black')
ax1.plot(ElectricityConsumption['2018-4-29'],color='black', marker='o',linestyle='--')
ax1.plot(ElectricityConsumption['2018-4-29']>0.5,color='black', marker='o',linestyle='')
#right axis
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
ax2.set_ylabel("Temperature in [°C]", color='blue',rotation=270,va="bottom")
ax2.plot(Temperature2['2018-4-29'],color='blue', marker='x',linestyle=':')
ax2.plot(Temperature2['2018-4-29']>5,color='blue', marker='x',linestyle='')
#
ax1.grid(True)
plt.title("Electricity consumption and air temperature in April 29, 2018") #title
#change x axis
xfmt = mdates.DateFormatter('%H:%M')
ax1.xaxis.set_major_formatter(xfmt)
#
plt.show()
#NOTE the "1" is different in the different energy and the temperature plots (check scales)
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:7: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
import sys
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:8: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:12: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
if sys.path[0] == '':
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:13: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
del sys.path[0]
#subplot function
#https://matplotlib.org/2.0.1/examples/api/two_scales.html
####
fig, ax1 = plt.subplots(figsize=(16,6))
#left axis
ax1.set_ylabel("Energy in [kWh]", color='black')
#ax1.plot(ElectricityConsumption['2018-4-29'],color='black', marker='o',linestyle='--')
ax1.plot(ElectricityConsumption['2018-4-29']>0.2,color='red', marker='o',linestyle='')
#right axis
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
ax2.set_ylabel("Temperature in [°C]", color='black',rotation=270,va="bottom")
#ax2.plot(Temperature2['2018-4-29'],color='blue', marker='x',linestyle=':')
ax2.plot(Temperature2['2018-4-29']>7,color='blue', marker='x',linestyle='')
#
ax1.grid(True)
plt.title("Electricity consumption and air temperature in April 29, 2018") #title
#change x axis
xfmt = mdates.DateFormatter('%H:%M')
ax1.xaxis.set_major_formatter(xfmt)
#
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:8: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:13: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
del sys.path[0]
#plotting
aux=(Temperature2['2018-4-29'].values>7) & (ElectricityConsumption['2018-4-29'].values>0.2)
aux2=(Temperature2['2018-4-29'].values>7) | (ElectricityConsumption['2018-4-29'].values>0.2)
plt.figure(figsize=(16,6))
#plt.plot(ElectricityConsumption['2018-4-29'].index, aux,color='black', marker='o',linestyle='')
plt.plot(ElectricityConsumption['2018-4-29'].index, aux2, color='green', marker='s',linestyle='')
plt.grid(True)
plt.show()
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:3: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.
This is separate from the ipykernel package so we can avoid doing imports until
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:6: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.