Assessing Climate data to understand¶
Climate change is impacting the way people live around the world
The DATA DESCRIPTION AND CITATION HERE 🛎️
In [1]:
# Import libraries
import holoviews as hv
import hvplot.pandas
import pandas as pd
In [2]:
NewDelhi_url = ('https://www.ncei.noaa.gov/access/services/data/v1?'
'dataset=daily-summaries'
'&dataTypes=PRCP,TAVG,TMAX,TMIN'
'&stations=IN022021900'
'&startDate=1901-01-01'
'&endDate=2025-07-27'
'&units=standard')
NewDelhi_url
Out[2]:
'https://www.ncei.noaa.gov/access/services/data/v1?dataset=daily-summaries&dataTypes=PRCP,TAVG,TMAX,TMIN&stations=IN022021900&startDate=1901-01-01&endDate=2025-07-27&units=standard'
Downloading and working with NCEI Data¶
Here we have used earthpy to download data from your API URL.
In [ ]:
# Download the climate data
New_delhi_df = pd.read_csv(
NewDelhi_url,
index_col='DATE',
parse_dates=True,
na_values=['NaN']
)
# Check that the download worked
New_delhi_df.head()
In [ ]:
New_delhi_df = New_delhi_df[['PRCP', 'TAVG','TMAX','TMIN']]
New_delhi_df
Out[ ]:
PRCP | TAVG | TMAX | TMIN | |
---|---|---|---|---|
DATE | ||||
1901-01-01 | 0.31 | NaN | NaN | NaN |
1901-01-02 | 0.00 | NaN | NaN | NaN |
1901-01-03 | 0.00 | NaN | NaN | NaN |
1901-01-04 | 0.00 | NaN | NaN | NaN |
1901-01-05 | 0.00 | NaN | NaN | NaN |
... | ... | ... | ... | ... |
2025-07-23 | NaN | 83.0 | 91.0 | 78.0 |
2025-07-24 | NaN | 89.0 | NaN | 77.0 |
2025-07-25 | NaN | 91.0 | NaN | 82.0 |
2025-07-26 | 0.00 | 90.0 | 98.0 | 81.0 |
2025-07-27 | NaN | 91.0 | 98.0 | 84.0 |
44566 rows × 4 columns
Data Subsetting¶
In [ ]:
# Subset the data 1975 - 2025
ND_1975_2025 = New_delhi_df['1975':'2025']
ND_1975_2025
Out[ ]:
PRCP | TAVG | TMAX | TMIN | |
---|---|---|---|---|
DATE | ||||
1975-01-01 | 0.63 | 52.0 | 55.0 | NaN |
1975-01-02 | 0.02 | 53.0 | 63.0 | 43.0 |
1975-01-03 | 0.00 | 52.0 | 64.0 | 45.0 |
1975-01-04 | 0.00 | 54.0 | 66.0 | 43.0 |
1975-01-05 | 0.00 | 53.0 | 68.0 | 43.0 |
... | ... | ... | ... | ... |
2025-07-23 | NaN | 83.0 | 91.0 | 78.0 |
2025-07-24 | NaN | 89.0 | NaN | 77.0 |
2025-07-25 | NaN | 91.0 | NaN | 82.0 |
2025-07-26 | 0.00 | 90.0 | 98.0 | 81.0 |
2025-07-27 | NaN | 91.0 | 98.0 | 84.0 |
18317 rows × 4 columns
Ploting the precpitation column (PRCP) vs time¶
In [ ]:
ND_1975_2025.plot(
y='PRCP',
title='NEW Delhi-Precipitation',
xlabel='Date ',
ylabel='Precipitation in (mm)')
Out[ ]:
<Axes: title={'center': 'NEW Delhi-Precipitation'}, xlabel='Date ', ylabel='Precipitation in (mm)'>
Plotting Average Temperature vs Time
In [ ]:
# Plot the temperature vs time
ND_1975_2025.plot(
y='TAVG',
title='NEW Delhi Average Temperature',
xlabel='Date ',
ylabel='Temperature in (Degree Farheinhite)'
)
Out[ ]:
<Axes: title={'center': 'NEW Delhi Average Temperature'}, xlabel='Date ', ylabel='Temperature in (Degree Farheinhite)'>
In [ ]:
# Write a function to convert Fahrenheit to Celsius
def fah_to_cel(fah):
"""Convert temperature to Celcius"""
return (fah-32)*5/9 # Put your equation in here
ND_1975_2025['Celcius'] = ND_1975_2025['TAVG'].apply(fah_to_cel)
ND_1975_2025
/tmp/ipykernel_1039/3902032077.py:6: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy ND_1975_2025['Celcius'] = ND_1975_2025['TAVG'].apply(fah_to_cel)
Out[ ]:
PRCP | TAVG | TMAX | TMIN | Celcius | |
---|---|---|---|---|---|
DATE | |||||
1975-01-01 | 0.63 | 52.0 | 55.0 | NaN | 11.111111 |
1975-01-02 | 0.02 | 53.0 | 63.0 | 43.0 | 11.666667 |
1975-01-03 | 0.00 | 52.0 | 64.0 | 45.0 | 11.111111 |
1975-01-04 | 0.00 | 54.0 | 66.0 | 43.0 | 12.222222 |
1975-01-05 | 0.00 | 53.0 | 68.0 | 43.0 | 11.666667 |
... | ... | ... | ... | ... | ... |
2025-07-23 | NaN | 83.0 | 91.0 | 78.0 | 28.333333 |
2025-07-24 | NaN | 89.0 | NaN | 77.0 | 31.666667 |
2025-07-25 | NaN | 91.0 | NaN | 82.0 | 32.777778 |
2025-07-26 | 0.00 | 90.0 | 98.0 | 81.0 | 32.222222 |
2025-07-27 | NaN | 91.0 | 98.0 | 84.0 | 32.777778 |
18317 rows × 5 columns
In [ ]:
# Write a function to convert Fahrenheit to Celsius
def fah_to_cel(fah):
"""Convert temperature to Celcius"""
return (fah-32)*5/9 # Put your equation in here
ND_1975_2025['Celcius_TMAX'] = ND_1975_2025['TMAX'].apply(fah_to_cel)
ND_1975_2025
/tmp/ipykernel_1039/1610806823.py:6: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy ND_1975_2025['Celcius_TMAX'] = ND_1975_2025['TMAX'].apply(fah_to_cel)
Out[ ]:
PRCP | TAVG | TMAX | TMIN | Celcius | Celcius_TMAX | |
---|---|---|---|---|---|---|
DATE | ||||||
1975-01-01 | 0.63 | 52.0 | 55.0 | NaN | 11.111111 | 12.777778 |
1975-01-02 | 0.02 | 53.0 | 63.0 | 43.0 | 11.666667 | 17.222222 |
1975-01-03 | 0.00 | 52.0 | 64.0 | 45.0 | 11.111111 | 17.777778 |
1975-01-04 | 0.00 | 54.0 | 66.0 | 43.0 | 12.222222 | 18.888889 |
1975-01-05 | 0.00 | 53.0 | 68.0 | 43.0 | 11.666667 | 20.000000 |
... | ... | ... | ... | ... | ... | ... |
2025-07-23 | NaN | 83.0 | 91.0 | 78.0 | 28.333333 | 32.777778 |
2025-07-24 | NaN | 89.0 | NaN | 77.0 | 31.666667 | NaN |
2025-07-25 | NaN | 91.0 | NaN | 82.0 | 32.777778 | NaN |
2025-07-26 | 0.00 | 90.0 | 98.0 | 81.0 | 32.222222 | 36.666667 |
2025-07-27 | NaN | 91.0 | 98.0 | 84.0 | 32.777778 | 36.666667 |
18317 rows × 6 columns
In [ ]:
# Resample the data to look at yearly mean values
ND_1975_2025_mean = ND_1975_2025.resample('Y-Jul').mean()
ND_1975_2025_mean
/tmp/ipykernel_1039/1138109287.py:2: FutureWarning: 'Y-Jul' is deprecated and will be removed in a future version, please use 'YE-JUL' instead. ND_1975_2025_mean = ND_1975_2025.resample('Y-Jul').mean()
Out[ ]:
PRCP | TAVG | TMAX | TMIN | Celcius | Celcius_TMAX | |
---|---|---|---|---|---|---|
DATE | ||||||
1975-07-31 | 0.031364 | 78.213270 | 87.983784 | 66.424419 | 25.674039 | 31.102102 |
1976-07-31 | NaN | 75.941667 | 86.789474 | 65.169960 | 24.412037 | 30.438596 |
1977-07-31 | 0.075771 | 76.384615 | 87.232198 | 67.097701 | 24.658120 | 30.684555 |
1978-07-31 | 0.068562 | 76.860274 | 87.099099 | 66.226766 | 24.922374 | 30.610611 |
1979-07-31 | 0.112605 | 76.413699 | 87.763533 | 66.515152 | 24.674277 | 30.979740 |
1980-07-31 | 0.061532 | 77.773224 | 89.571831 | 66.175325 | 25.429569 | 31.984351 |
1981-07-31 | 0.066817 | 77.227397 | 88.274238 | 65.944954 | 25.126332 | 31.263466 |
1982-07-31 | 0.079267 | 75.597260 | 86.843575 | 64.944984 | 24.220700 | 30.468653 |
1983-07-31 | 0.043962 | 75.591781 | 86.807910 | 64.770898 | 24.217656 | 30.448839 |
1984-07-31 | 0.051622 | 76.480769 | 88.347458 | 64.974359 | 24.711538 | 31.304143 |
1985-07-31 | 0.105504 | 76.778082 | 89.487395 | 65.520124 | 24.876712 | 31.937442 |
1986-07-31 | 0.055165 | 75.887671 | 87.169444 | 64.790850 | 24.382040 | 30.649691 |
1987-07-31 | 0.036322 | 77.335165 | 89.305556 | 65.902821 | 25.186203 | 31.836420 |
1988-07-31 | 0.053166 | 78.084699 | 90.569405 | 66.459732 | 25.602611 | 32.538558 |
1989-07-31 | 0.089492 | 76.033708 | 88.658385 | 64.842657 | 24.463171 | 31.476881 |
1990-07-31 | 0.051074 | 76.194521 | 87.842262 | 65.731707 | 24.552511 | 31.023479 |
1991-07-31 | 0.068505 | 76.985380 | 90.146429 | 67.775785 | 24.991878 | 32.303571 |
1992-07-31 | 0.105891 | 75.465839 | 87.228782 | 64.357798 | 24.147688 | 30.682657 |
1993-07-31 | 0.065094 | 76.264957 | 88.289231 | 64.283276 | 24.591643 | 31.271795 |
1994-07-31 | 0.133053 | 76.679558 | 88.438235 | 65.669967 | 24.821977 | 31.354575 |
1995-07-31 | 0.050982 | 76.779006 | 88.492754 | 65.423676 | 24.877225 | 31.384863 |
1996-07-31 | 0.140979 | 76.450820 | 88.091691 | 65.345161 | 24.694900 | 31.162050 |
1997-07-31 | 0.064636 | 74.616438 | 86.890805 | 62.874194 | 23.675799 | 30.494891 |
1998-07-31 | 0.075732 | 75.526027 | 86.696793 | 65.515358 | 24.181126 | 30.387107 |
1999-07-31 | 0.173099 | 76.588889 | 88.157100 | 66.423729 | 24.771605 | 31.198389 |
2000-07-31 | 0.117425 | 76.314208 | 88.356083 | 65.564014 | 24.619004 | 31.308935 |
2001-07-31 | 0.216301 | 76.134615 | 88.365439 | 64.919463 | 24.519231 | 31.314133 |
2002-07-31 | 0.288222 | 78.013699 | 90.787966 | 66.882911 | 25.563166 | 32.659981 |
2003-07-31 | 0.133197 | 76.230769 | 88.123944 | 65.522876 | 24.572650 | 31.179969 |
2004-07-31 | 0.039466 | 76.833333 | 88.669492 | 66.058632 | 24.907407 | 31.483051 |
2005-07-31 | 0.078266 | 76.668493 | 88.438889 | 65.624615 | 24.815830 | 31.354938 |
2006-07-31 | 0.387321 | 77.194521 | 90.087079 | 64.882175 | 25.108067 | 32.270599 |
2007-07-31 | 0.262676 | 77.109890 | 89.081461 | 66.589172 | 25.061050 | 31.711923 |
2008-07-31 | 0.265217 | 75.807692 | 88.498615 | 64.715686 | 24.337607 | 31.388119 |
2009-07-31 | 0.262754 | 77.887671 | 90.814085 | 66.996914 | 25.493151 | 32.674491 |
2010-07-31 | 0.307468 | 78.155125 | 90.468750 | 67.394984 | 25.641736 | 32.482639 |
2011-07-31 | 0.344157 | 76.000000 | 88.014085 | 65.839117 | 24.444444 | 31.118936 |
2012-07-31 | 0.219556 | 77.363388 | 90.200549 | 66.557994 | 25.201882 | 32.333639 |
2013-07-31 | 0.395960 | 76.312329 | 88.949721 | 65.288344 | 24.617960 | 31.638734 |
2014-07-31 | 0.229000 | 76.605479 | 88.867403 | 65.573574 | 24.780822 | 31.593002 |
2015-07-31 | 0.239398 | 76.915068 | 89.275568 | 65.740625 | 24.952816 | 31.819760 |
2016-07-31 | 0.281053 | 79.704110 | 90.569288 | 67.660131 | 26.502283 | 32.538494 |
2017-07-31 | 0.253368 | 79.680441 | 91.095506 | 66.990536 | 26.489134 | 32.830836 |
2018-07-31 | 0.206949 | 78.227397 | 91.599119 | 66.394984 | 25.681887 | 33.110622 |
2019-07-31 | 0.245085 | 77.814404 | 89.336842 | 64.219048 | 25.452447 | 31.853801 |
2020-07-31 | 0.291262 | 76.707650 | 88.186603 | 65.486068 | 24.837583 | 31.214779 |
2021-07-31 | 0.420805 | 77.828729 | 90.965174 | 63.768997 | 25.460405 | 32.758430 |
2022-07-31 | 0.359885 | 77.805479 | 92.587786 | 66.148607 | 25.447489 | 33.659881 |
2023-07-31 | 0.350476 | 76.164384 | 89.472727 | 64.252226 | 24.535769 | 31.929293 |
2024-07-31 | 0.324384 | 77.234463 | 90.815686 | 65.532915 | 25.130257 | 32.675381 |
2025-07-31 | 0.329070 | 77.312676 | 90.790393 | 66.296774 | 25.173709 | 32.661329 |
Plot resampled data 📈
In [ ]:
# Plot mean annual temperature values
# using hvplot
import hvplot.pandas
(ND_1975_2025.hvplot(
y='Celcius',
title='NEW Delhi Mean Annual Temperature',
xlabel='DATE',
ylabel='Temperature in (C)')
+
ND_1975_2025_mean.hvplot(
y='Celcius',
title='New Delhi Mean Annual Temperature',
xlabel='DATE',
ylabel='Temperature in (C)',shared_axes=False)).cols(1)
Out[ ]:
In [ ]:
# Plot Annual Max temperature values
# using hvplot
import hvplot.pandas
(ND_1975_2025.hvplot(
y='Celcius_TMAX',
title='New Delhi Annual Maximum Temperature',
xlabel='DATE',
ylabel='Temperature in (C)')
+
ND_1975_2025_mean.hvplot(
y='Celcius_TMAX',
title='New Delhi Annual Maximum Temperature',
xlabel='DATE',
ylabel='Temperature in (C)',shared_axes=False)).cols(1)
Out[ ]:
Storing variables¶
In [ ]:
%store ND_1975_2025 ND_1975_2025_mean NewDelhi_url New_delhi_df
Stored 'ND_1975_2025' (DataFrame) Stored 'ND_1975_2025_mean' (DataFrame) Stored 'NewDelhi_url' (str) Stored 'New_delhi_df' (DataFrame)
In [ ]:
%%capture
%%bash
#Coverting to HTML
jupyter nbconvert climate-98-download.ipynb --to html
Finally, be sure to Restart
and Run all
to make sure your notebook
works all the way through!