import pandas as pd
from pandas import *
import numpy as np
import plotnine as p9
from plotnine import *
import seaborn as sns
import matplotlib.pyplot as plt
import datetime
from datetime import *
3 Time Series Graphics
3.1 Task 1
- Get data from tsibbledata package in R and write it as a csv file
Following is an R code.
#install.packages("tsibbledata")
library(tsibbledata)
library(tidyverse)
data(olympic_running)
write_csv(olympic_running, file="data/olympic_running.csv")
- Read data
= pd.read_csv('data/olympic_running.csv', parse_dates=['Year'])
olympic_running olympic_running
Year | Length | Sex | Time | |
---|---|---|---|---|
0 | 1896-01-01 | 100 | men | 12.00 |
1 | 1900-01-01 | 100 | men | 11.00 |
2 | 1904-01-01 | 100 | men | 11.00 |
3 | 1908-01-01 | 100 | men | 10.80 |
4 | 1912-01-01 | 100 | men | 10.80 |
... | ... | ... | ... | ... |
307 | 2000-01-01 | 10000 | women | 1817.49 |
308 | 2004-01-01 | 10000 | women | 1824.36 |
309 | 2008-01-01 | 10000 | women | 1794.66 |
310 | 2012-01-01 | 10000 | women | 1820.75 |
311 | 2016-01-01 | 10000 | women | 1757.45 |
312 rows × 4 columns
Task: Visualise data in a meaningful way.
3.2 Task 2
Obtain vic_elec
data from the tsibbledata
package in R and visualize.
Help
import pandas as pd
= pd.read_csv('data/vic_elec.csv', parse_dates=['Time'])
vic_elec vic_elec
Time | Demand | Temperature | Date | Holiday | |
---|---|---|---|---|---|
0 | 2011-12-31 13:00:00+00:00 | 4382.825174 | 21.40 | 2012-01-01 | True |
1 | 2011-12-31 13:30:00+00:00 | 4263.365526 | 21.05 | 2012-01-01 | True |
2 | 2011-12-31 14:00:00+00:00 | 4048.966046 | 20.70 | 2012-01-01 | True |
3 | 2011-12-31 14:30:00+00:00 | 3877.563330 | 20.55 | 2012-01-01 | True |
4 | 2011-12-31 15:00:00+00:00 | 4036.229746 | 20.40 | 2012-01-01 | True |
... | ... | ... | ... | ... | ... |
52603 | 2014-12-31 10:30:00+00:00 | 3873.448714 | 19.00 | 2014-12-31 | False |
52604 | 2014-12-31 11:00:00+00:00 | 3791.637322 | 18.50 | 2014-12-31 | False |
52605 | 2014-12-31 11:30:00+00:00 | 3724.835666 | 17.70 | 2014-12-31 | False |
52606 | 2014-12-31 12:00:00+00:00 | 3761.886854 | 17.30 | 2014-12-31 | False |
52607 | 2014-12-31 12:30:00+00:00 | 3809.414586 | 17.10 | 2014-12-31 | False |
52608 rows × 5 columns
vic_elec.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 52608 entries, 0 to 52607
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Time 52608 non-null datetime64[ns, UTC]
1 Demand 52608 non-null float64
2 Temperature 52608 non-null float64
3 Date 52608 non-null object
4 Holiday 52608 non-null bool
dtypes: bool(1), datetime64[ns, UTC](1), float64(2), object(1)
memory usage: 1.7+ MB