Analyzing River Thames Water Levels
Time series data is everywhere, from watching your stock portfolio to monitoring climate change, and even live-tracking as local cases of a virus become a global pandemic. In this project, you’ll work with a time series that tracks the tide levels of the Thames River. You’ll first load the data and inspect it data visually, and then perform calculations on the dataset to generate some summary statistics. You’ll end by reducing the time series to its component attributes and analyzing them.
The original dataset is available from the British Oceanographic Data Center.
Here's a map of the locations of the tidal meters along the River Thames in London.
The provided datasets are in the data folder in this workspace. For this project, you will work with one of these files, 10-11_London_Bridge.txt, which contains comma separated values for water levels in the Thames River at the London Bridge. After you've finished the project, you can use your same code to analyze data from the other files (at other spots in the UK where tidal data is collected) if you'd like.
The TXT file contains data for three variables, described in the table below.
| Variable Name | Description | Format |
|---|---|---|
| Date and time | Date and time of measurement to GMT. Note the tide gauge is accurate to one minute. | dd/mm/yyyy hh:mm:ss |
| Water level | High or low water level measured by tide meter. Tide gauges are accurate to 1 centimetre. | metres (Admiralty Chart Datum (CD), Ordnance Datum Newlyn (ODN or Trinity High Water (THW)) |
| Flag | High water flag = 1, low water flag = 0 | Categorical (0 or 1) |
# We've imported your first Python package for you, along with a function you will need called IQR
import pandas as pd
def IQR(column):
""" Calculates the interquartile range (IQR) for a given DataFrame column using the quantile method """
q25, q75 = column.quantile([0.25, 0.75])
return q75-q25
# Begin coding here ...1 - Load and filter data from London Bridge
# How to read a TXT file with pandas
london_df = pd.read_csv('data/10-11_London_Bridge.txt')
print(london_df.head())
print(london_df.info())# Working with only the first n columns of a DataFrame
london_df = london_df.iloc[:, :3]
london_df.head()# Renaming columns of a DataFrame
london_df.columns = ['datetime', 'water_level', 'is_high_tide']
london_df.head()2 - Preparing DataFrame columns for analysis
# Converting a column to a datetime data type
london_df['datetime'] = pd.to_datetime(london_df['datetime'], format='%d/%m/%Y %H:%M:%S')# Converting a column to a float data type
london_df['water_level'] = london_df['water_level'].astype(float)london_df.info()# Extracting date parts from a datetime column - month and year
london_df['month'] = london_df['datetime'].dt.month
london_df['year'] = london_df['datetime'].dt.year
london_df.head()3 - Separating a DataFrame for high- and low-tide water levels
# Filtering a DataFrame for particular column values
low_tide_df = london_df[london_df['is_high_tide'] == 0]
high_tide_df = london_df[london_df['is_high_tide'] == 1]
print(low_tide_df.head())
print(high_tide_df.head())print(low_tide_df.shape)
print(high_tide_df.shape)4 - Finding summary statistics for the high- and low-tide data