import sys
import numpy as np
import pandas as pd
from IPython.display import display, Markdown
import matplotlib.pyplot as plt
import seaborn as sns
set()
sns."whitegrid")
sns.set_style(
import random
= 5
random_seed
'..')
sys.path.append(from global_params import load_params
Danish weather
Import some plotting libraries and set some defaults:
Tip:
Producing figures in svg format (scalable vector graphics) makes for sharp plots on webpages. However, if you make plots with thousands of observations you should set this to'png'
instead:
%config InlineBackend.figure_formats = ['svg']
Tip:
Some values apply globally to your analysis. E.g., sample sizes, cutoffs, names, rates, etc. Keeping those in a a yml file likeweather_params.yml
and loading them in each notebook avoids the risk of manually adding/updating them in each notebook where they are used. You can use theload_globals
function imported above fromglobal_params.py
to produce an object holding all the global values:
= load_params('../weather_params.yml')
params params
{'nr_project_days': 150}
params.nr_project_days
150
Here is some computation:
= 150
nr_project_days = pd.DataFrame({'day': list(range(nr_project_days)),
df 'wind': [random.random()+1 for i in range(nr_project_days)],
'precipitation': [random.random()+1 for i in range(nr_project_days)]})
df
day | wind | precipitation | |
---|---|---|---|
0 | 0 | 1.013950 | 1.900108 |
1 | 1 | 1.433512 | 1.612078 |
2 | 2 | 1.465184 | 1.844704 |
3 | 3 | 1.438446 | 1.120334 |
4 | 4 | 1.052238 | 1.491236 |
... | ... | ... | ... |
145 | 145 | 1.071599 | 1.038249 |
146 | 146 | 1.884493 | 1.853783 |
147 | 147 | 1.743312 | 1.075927 |
148 | 148 | 1.794445 | 1.605397 |
149 | 149 | 1.266453 | 1.681632 |
150 rows × 3 columns
Weather data
Weather data was collected… blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah
= df.melt(id_vars=['day'], value_vars=['wind', 'precipitation'], var_name='weather', value_name='value')
long_format long_format
day | weather | value | |
---|---|---|---|
0 | 0 | wind | 1.013950 |
1 | 1 | wind | 1.433512 |
2 | 2 | wind | 1.465184 |
3 | 3 | wind | 1.438446 |
4 | 4 | wind | 1.052238 |
... | ... | ... | ... |
295 | 145 | precipitation | 1.038249 |
296 | 146 | precipitation | 1.853783 |
297 | 147 | precipitation | 1.075927 |
298 | 148 | precipitation | 1.605397 |
299 | 149 | precipitation | 1.681632 |
300 rows × 3 columns
=long_format, x='day', y='value', hue='weather')
sns.lineplot(data=0) ; plt.ylim(bottom
From this plot, it seems Danish weather is quite unpredictable.