Exercise E: Pandas timeseries#
2021-8-24
import numpy as np
import pandas as pd
E.1 Read time series from csv#
# read Klagshamn_water_level.csv with to a DataFrame df using pd.read_csv
# print first 5 rows of df and check the type of the index
# read Klagshamn_water_level.csv again to df
# now with the arguments index_col=0, parse_dates=True
# print first 5 rows of df and check the type of the index
# plot df using df.plot()
# find the min and max value of the time series
# check if there are any NaN values in the series (hist: .isna() )
# use .resample('D') to get daily values max() values
# use .plot.bar() to to plot the daily max values as a bar chart
E.2 Create new time series#
Read pandas.date_range
# create a DateTimeIndex using pd.date_range. Check the documentation for help.
# It should be hourly starting at '2015-01-01' and ending at '2015-01-15'
# Call the new index "idx"
# Create an empty DataFrame df2 with this index pd.DataFrame(index=...)
# Add a column called "ones" with the value 1.0
# Add a column "sin" by taking np.sin() of pi*hour/12
# Hint: you get the hour value of idx by taking idx.hour
# plot the time series