14  practice

Dowload this dataset for the weather in Reykjavík, Iceland from January 1st to December 31st, 1990.

Use the following code to load the dataset:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

filename = "../archive/data/Reykjaviik1990.csv"
df = pd.read_csv(filename, parse_dates=['time'], index_col='time')
# convert column temperature_2m from kelvin to celsius
df['temperature_2m'] = df['temperature_2m'] - 273.15
df
longitude latitude temperature_2m dewpoint_temperature_2m volumetric_soil_water_layer_1 volumetric_soil_water_layer_2 volumetric_soil_water_layer_3 total_precipitation surface_net_solar_radiation potential_evaporation
time
1990-01-01 00:00:00 -21.707789 64.072338 4.371652 277.083878 0.367294 0.347504 0.282730 0.012072 53890.0 -0.005887
1990-01-01 01:00:00 -21.707789 64.072338 4.441705 277.134430 0.362778 0.349655 0.283630 0.000704 0.0 -0.000216
1990-01-01 02:00:00 -21.707789 64.072338 4.378412 277.056793 0.361160 0.350479 0.284637 0.001431 0.0 -0.000445
1990-01-01 03:00:00 -21.707789 64.072338 4.262323 276.934082 0.360275 0.350983 0.285645 0.002198 0.0 -0.000681
1990-01-01 04:00:00 -21.707789 64.072338 4.136362 276.805954 0.360733 0.351486 0.286667 0.003100 0.0 -0.000920
... ... ... ... ... ... ... ... ... ... ...
1990-12-30 19:00:00 -21.707789 64.072338 -11.145605 257.818130 0.244446 0.246048 0.264557 0.000062 137160.0 -0.000774
1990-12-30 20:00:00 -21.707789 64.072338 -10.969962 258.685898 0.244370 0.245972 0.264374 0.000062 137160.0 -0.000778
1990-12-30 21:00:00 -21.707789 64.072338 -10.729712 259.601089 0.244278 0.245895 0.264175 0.000062 137160.0 -0.000776
1990-12-30 22:00:00 -21.707789 64.072338 -10.529898 260.376083 0.244247 0.245819 0.263992 0.000062 137160.0 -0.000770
1990-12-30 23:00:00 -21.707789 64.072338 -10.341437 261.098175 0.244247 0.245728 0.263824 0.000062 137160.0 -0.000761

8736 rows × 10 columns

fig, ax = plt.subplots()
ax.plot(df['temperature_2m'])

fig, ax = plt.subplots()
ax.plot(df['total_precipitation'])

14.1 smoothing

Make the following graphs:

  1. A line plot of the temperature in Reykjavík, Iceland from January 1st to December 31st, 1990.
  2. Make a smoothed temperature line on top of this, using varying window sizes.
  3. Make a new graph, now use rolling together with other functions. Plot the mean, min and max temperatures.

14.2 custom function

Write the following custom functions: 1. receives as an argument a temperature dataframe column, and returns the number of rows inside this column that are below 0 degrees. 1. receives as an argument a temperature dataframe column, and returns the fraction of time inside this column where temperature is below 0 degrees.