3.2. Pandas Exercise#
Create a DataFrame by reading the file ../../assets/data/Changi_daily_rainfall.csv. Perform the following two tasks with this DataFrame.
3.2.1. Task 1#
Determine whether the dataframe contains
NaN
values. If so, fill theNaN
values with the previous day’s value.Show the first 5 rows and the last 3 rows. Check the data length.
For each year, calculate the frequency (i.e., number of days) of rainfall events whose magnitude exceeds 0.1 mm/day.
Find the three months with the highest/lowest long-term averaged monthly rainfall. Are these months within your expection (e.g., Singapore’s monsoon seasons)?
Note: If you want to do this task on your local computer (not recommended), please modify the file path accordingly.
# Your solutions go here. Create a separate code chunk for each question.
# using the + icon to add a cell in the toolbar.
3.2.2. Task 2#
Resample the DataFrame from daily time scale to annual time scale. Calculate the annual total rainfall for each year.
Compare the long-term averaged annual rainfall in two periods: 1981-2000 and 2001-2020.
Find the year with the largest/smallest annual rainfall and print their values.
Calculate the trend of annual rainfall during 1981-2020 using the following formula:
where \(a\) is the trend of annual rainfall, \(x\) is year, \(y\) is annual rainfall, and \(n\) is the number of years.
# Your solutions go here. Create a separate code chunk for each question
# using the + icon to add a cell in the toolbar.