USGS dataretrieval Python Package get_qwdata() Examples

This notebook provides examples of using the Python dataretrieval package to retrieve water quality sample data for United States Geological Survey (USGS) monitoring sites. The dataretrieval package provides a collection of functions to get data from the USGS National Water Information System (NWIS) and other online sources of hydrology and water quality data, including the United States Environmental Protection Agency (USEPA).

Install the Package

Use the following code to install the package if it doesn’t exist already within your Jupyter Python environment.

[1]:
!pip install dataretrieval
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: dataretrieval in /home/runner/.local/lib/python3.10/site-packages (0.1.dev1+g3ba0c83)
Requirement already satisfied: requests in /home/runner/.local/lib/python3.10/site-packages (from dataretrieval) (2.32.3)
Requirement already satisfied: pandas==2.* in /home/runner/.local/lib/python3.10/site-packages (from dataretrieval) (2.2.3)
Requirement already satisfied: numpy>=1.22.4 in /home/runner/.local/lib/python3.10/site-packages (from pandas==2.*->dataretrieval) (2.1.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/runner/.local/lib/python3.10/site-packages (from pandas==2.*->dataretrieval) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /usr/lib/python3/dist-packages (from pandas==2.*->dataretrieval) (2022.1)
Requirement already satisfied: tzdata>=2022.7 in /home/runner/.local/lib/python3.10/site-packages (from pandas==2.*->dataretrieval) (2024.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/runner/.local/lib/python3.10/site-packages (from requests->dataretrieval) (3.4.0)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests->dataretrieval) (3.3)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/lib/python3/dist-packages (from requests->dataretrieval) (1.26.5)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests->dataretrieval) (2020.6.20)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.8.2->pandas==2.*->dataretrieval) (1.16.0)

Load the package so you can use it along with other packages used in this notebook.

[2]:
from dataretrieval import nwis
from IPython.display import display

Basic Usage

The dataretrieval package has several functions that allow you to retrieve data from different web services. This examples uses the get_qwdata() function to retrieve water quality sample data for USGS monitoring sites from NWIS. The following arguments are supported:

Arguments (Additional arguments, if supplied, will be used as query parameters)

  • sites (string or list of strings): A list of USGS site identifiers for which to retrieve data. If the qwdata parameter site_no is supplied, it will overwrite the sites parameter.

  • parameterCd (string or list of strings): A list of USGS parameter codes for which to retrieve data.

  • start (string): The beginning date for a period for which to retrieve data. If the qwdata parameter begin_date is supplied, it will overwrite the start parameter.

  • end (string): The ending date for a period for which to retrieve data. If the qwdata parameter end_date is supplied, it will overwrite the end parameter.

  • datetime_index (boolean): If True, create a datetime index

  • wide_format (boolean): If True, return data in wide format with multiple samples per row and one row per time.

Example 1: Get all water quality sample data for a single monitoring site

[3]:
siteID = '10109000'
wq_data = nwis.get_qwdata(sites=siteID)
print('Retrieved data for ' + str(len(wq_data[0])) + ' samples.')
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/nwis.py:193: UserWarning: WARNING: Starting in March 2024, the NWIS qw data endpoint is retiring and no longer receives updates. For more information, refer to https://waterdata.usgs.gov.nwis/qwdata and https://doi-usgs.github.io/dataRetrieval/articles/Status.html or email CompTools@usgs.gov.
  warnings.warn(
Retrieved data for 345 samples.
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/utils.py:90: UserWarning: Warning: 7 incomplete dates found, consider setting datetime_index to False.
  warnings.warn(

Interpreting the Result

The result of calling the get_qwdata() function is an object that contains a Pandas data frame object and an associated metadata object. The Pandas data frame contains the water quality sample data for the requested site, and or observed variables and time frame.

Once you’ve got the data frame, there’s several useful things you can do to explore the data.

Display the data frame as a table. The default data frame for this function is a wide, cross-tabulated table, with columns for each observed variable and a row for each sample date (wide_format=True).

[4]:
display(wq_data[0])
agency_cd site_no sample_dt sample_tm sample_end_dt sample_end_tm sample_start_time_datum_cd tm_datum_rlbty_cd coll_ent_cd medium_cd ... p70300 p70301 p70302 p70303 p71851 p71999 p81903 p82398 p84164 p99111
datetime
1967-09-13 13:35:00+00:00 USGS 10109000 1967-09-13 07:35 NaN NaN -0600 T NaN WS ... 196.0 NaN 108.0 0.27 0.1 NaN NaN NaN NaN NaN
1968-01-18 19:20:00+00:00 USGS 10109000 1968-01-18 12:20 NaN NaN -0700 T NaN WS ... 210.0 NaN 63.5 0.29 0.5 NaN NaN NaN NaN NaN
1968-05-15 18:30:00+00:00 USGS 10109000 1968-05-15 12:30 NaN NaN -0600 T NaN WS ... 155.0 156.0 151.0 0.21 0.6 NaN NaN NaN NaN NaN
1968-07-26 20:40:00+00:00 USGS 10109000 1968-07-26 14:40 NaN NaN -0600 T NaN WS ... 189.0 188.0 135.0 0.26 0.3 NaN NaN NaN NaN NaN
1972-12-08 23:15:00+00:00 USGS 10109000 1972-12-08 16:15 NaN NaN -0700 T NaN WS ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
NaT USGS 10109000 1988-11-28 NaN NaN NaN -0700 T USGS-WRD WS ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-04-27 NaN NaN NaN -0600 T USGS-WRD WS ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-07-28 NaN NaN NaN -0600 T USGS-WRD WS ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-08-31 NaN NaN NaN -0600 T USGS-WRD WS ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-10-05 NaN NaN NaN -0600 T USGS-WRD WS ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

345 rows × 60 columns

Show the data types of the columns in the resulting data frame.

[5]:
print(wq_data[0].dtypes)
agency_cd                      object
site_no                        object
sample_dt                      object
sample_tm                      object
sample_end_dt                 float64
sample_end_tm                 float64
sample_start_time_datum_cd     object
tm_datum_rlbty_cd              object
coll_ent_cd                    object
medium_cd                      object
project_cd                     object
aqfr_cd                       float64
tu_id                         float64
body_part_id                  float64
hyd_cond_cd                    object
samp_type_cd                    int64
hyd_event_cd                    int64
sample_lab_cm_txt             float64
p00003                        float64
p00004                        float64
p00009                        float64
p00010                        float64
p00020                         object
p00028                        float64
p00060                        float64
p00061                        float64
p00065                        float64
p00095                        float64
p00191                        float64
p00400                        float64
p00405                        float64
p00410                        float64
p00440                        float64
p00445                        float64
p00618                        float64
p00660                        float64
p00900                        float64
p00902                        float64
p00915                        float64
p00925                        float64
p00931                        float64
p00932                        float64
p00933                        float64
p00940                        float64
p00945                        float64
p00955                        float64
p30207                        float64
p30208                        float64
p30209                        float64
p50280                         object
p70300                        float64
p70301                        float64
p70302                        float64
p70303                        float64
p71851                        float64
p71999                        float64
p81903                        float64
p82398                        float64
p84164                        float64
p99111                        float64
dtype: object

The other part of the result returned from the get_qwdata() function is a metadata object that contains information about the query that was executed to return the data. For example, you can access the URL that was assembled to retrieve the requested data from the USGS web service. The USGS web service responses contain a descriptive header that defines and can be helpful in interpreting the contents of the response.

[6]:
print('The query URL used to retrieve the data from NWIS was: ' + wq_data[1].url)
The query URL used to retrieve the data from NWIS was: https://nwis.waterdata.usgs.gov/nwis/qwdata?site_no=10109000&qw_sample_wide=qw_sample_wide&agency_cd=USGS&format=rdb&pm_cd_compare=Greater+than&inventory_output=0&rdb_inventory_output=file&TZoutput=0&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD&rdb_compression=value&submitted_form=brief_list

Additional Examples

Example 2: Get water quality sample data for multiple sites for a single parameter

[7]:
site_ids = ['04024430', '04024000']
parameter_code = '00065'
wq_multi_site = nwis.get_qwdata(sites=site_ids, parameterCd=parameter_code)
print('Retrieved data for ' + str(len(wq_multi_site[0])) + ' samples.')
display(wq_multi_site[0])
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/nwis.py:193: UserWarning: WARNING: Starting in March 2024, the NWIS qw data endpoint is retiring and no longer receives updates. For more information, refer to https://waterdata.usgs.gov.nwis/qwdata and https://doi-usgs.github.io/dataRetrieval/articles/Status.html or email CompTools@usgs.gov.
  warnings.warn(
Retrieved data for 281 samples.
agency_cd sample_dt sample_tm sample_end_dt sample_end_tm sample_start_time_datum_cd tm_datum_rlbty_cd coll_ent_cd medium_cd project_cd aqfr_cd tu_id body_part_id hyd_cond_cd samp_type_cd hyd_event_cd sample_lab_cm_txt p00065
site_no datetime
04024000 1984-04-24 14:30:00+00:00 USGS 1984-04-24 08:30 NaN NaN -0600 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 4.62
1984-06-19 15:15:00+00:00 USGS 1984-06-19 10:15 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 6.43
1984-08-22 15:45:00+00:00 USGS 1984-08-22 10:45 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 3.24
1985-02-11 20:30:00+00:00 USGS 1985-02-11 14:30 NaN NaN -0600 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 3.51
2010-10-07 15:45:00+00:00 USGS 2010-10-07 10:45 2010-11-02 10:15 -0500 K USGS-WRD WS GR11NQ00E NaN NaN NaN 4 9 9 NaN 3.11
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
04024430 1983-04-19 16:00:00+00:00 USGS 1983-04-19 10:00 NaN NaN -0600 T USGS-WRD WS NaN NaN NaN NaN A 9 9 NaN 8.83
1983-05-24 21:10:00+00:00 USGS 1983-05-24 16:10 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 5.64
1983-07-06 17:00:00+00:00 USGS 1983-07-06 12:00 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 5 9 9 NaN 12.59
1983-08-16 19:20:00+00:00 USGS 1983-08-16 14:20 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 5.23
2007-10-09 22:00:00+00:00 USGS 2007-10-09 17:00 NaN NaN -0500 K USGS-WRD SS NaN NaN NaN NaN 5 9 7 NaN 10.92

281 rows × 18 columns

The following example is the same as the previous example but with multi index turned off (multi_index=False)

[8]:
site_ids = ['04024430', '04024000']
parameter_code = '00065'
wq_multi_site = nwis.get_qwdata(sites=site_ids, parameterCd=parameter_code, multi_index=False)
print('Retrieved data for ' + str(len(wq_multi_site[0])) + ' samples.')
display(wq_multi_site[0])
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/nwis.py:193: UserWarning: WARNING: Starting in March 2024, the NWIS qw data endpoint is retiring and no longer receives updates. For more information, refer to https://waterdata.usgs.gov.nwis/qwdata and https://doi-usgs.github.io/dataRetrieval/articles/Status.html or email CompTools@usgs.gov.
  warnings.warn(
Retrieved data for 281 samples.
agency_cd site_no sample_dt sample_tm sample_end_dt sample_end_tm sample_start_time_datum_cd tm_datum_rlbty_cd coll_ent_cd medium_cd project_cd aqfr_cd tu_id body_part_id hyd_cond_cd samp_type_cd hyd_event_cd sample_lab_cm_txt p00065
datetime
1982-11-02 20:10:00+00:00 USGS 04024430 1982-11-02 14:10 NaN NaN -0600 T USGS-GAL WS NaN NaN NaN NaN A 9 9 NaN 5.72
1983-01-18 18:30:00+00:00 USGS 04024430 1983-01-18 12:30 NaN NaN -0600 T USGS-GAL WS NaN NaN NaN NaN A 9 9 NaN 6.17
1983-04-19 16:00:00+00:00 USGS 04024430 1983-04-19 10:00 NaN NaN -0600 T USGS-WRD WS NaN NaN NaN NaN A 9 9 NaN 8.83
1983-05-24 21:10:00+00:00 USGS 04024430 1983-05-24 16:10 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 9 9 9 NaN 5.64
1983-07-06 17:00:00+00:00 USGS 04024430 1983-07-06 12:00 NaN NaN -0500 T USGS-WRD WS NaN NaN NaN NaN 5 9 9 NaN 12.59
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2023-10-16 16:40:00+00:00 USGS 04024000 2023-10-16 11:40 NaN NaN -0500 K USGS-WRD WS Scanlon NaN NaN NaN 9 9 9 NaN 3.51
2023-11-20 15:25:00+00:00 USGS 04024000 2023-11-20 09:25 NaN NaN -0600 K USGS-WRD WS Scanlon NaN NaN NaN 9 9 9 NaN 4.21
2023-12-18 16:40:00+00:00 USGS 04024000 2023-12-18 10:40 NaN NaN -0600 K USGS-WRD WS Scanlon NaN NaN NaN 8 9 9 NaN 4.00
2024-01-08 17:00:00+00:00 USGS 04024000 2024-01-08 11:00 NaN NaN -0600 K USGS-WRD WS Scanlon NaN NaN NaN 5 9 9 NaN 4.54
2024-02-05 15:05:00+00:00 USGS 04024000 2024-02-05 09:05 NaN NaN -0600 K USGS-WRD WS Scanlon NaN NaN NaN 9 9 9 NaN 3.85

281 rows × 19 columns

Example 3: Retrieve water quality sample data for multiple sites, including a list of parameters, within a time period defined by start and end dates

[9]:
site_ids = ['04024430', '04024000']
parameterCd = ['34247', '30234', '32104', '34220']
startDate = '2012-01-01'
endDate = ''
wq_data2 = nwis.get_qwdata(sites=site_ids, parameterCd=parameterCd,
                           start=startDate, end=endDate)
print('Retrieved data for ' + str(len(wq_multi_site[0])) + ' samples.')
display(wq_data2[0])

/home/runner/.local/lib/python3.10/site-packages/dataretrieval/nwis.py:193: UserWarning: WARNING: Starting in March 2024, the NWIS qw data endpoint is retiring and no longer receives updates. For more information, refer to https://waterdata.usgs.gov.nwis/qwdata and https://doi-usgs.github.io/dataRetrieval/articles/Status.html or email CompTools@usgs.gov.
  warnings.warn(
Retrieved data for 281 samples.
agency_cd sample_dt sample_tm sample_end_dt sample_end_tm sample_start_time_datum_cd tm_datum_rlbty_cd coll_ent_cd medium_cd project_cd ... tu_id body_part_id hyd_cond_cd samp_type_cd hyd_event_cd sample_lab_cm_txt p30234 p32104 p34220 p34247
site_no datetime
04024000 2012-01-25 14:40:00+00:00 USGS 2012-01-25 08:40 NaN NaN -0600 K USGS-WRD WS GR12NK00E ... NaN NaN 4 9 B A-0270113 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-02-22 14:45:00+00:00 USGS 2012-02-22 08:45 NaN NaN -0600 K USGS-WRD WS GR12NK00E ... NaN NaN 4 9 B A-0540032 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-03-12 13:55:00+00:00 USGS 2012-03-12 08:55 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 4 9 B A-0740087 ** Second GCC bottle (Sch 4433) is a... < 0.16 0.01 bt < 0.02 < 0.02
2012-03-27 13:55:00+00:00 USGS 2012-03-27 08:55 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 9 9 A A-0900013 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-04-17 14:20:00+00:00 USGS 2012-04-17 09:20 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 8 9 J A-1110047 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-04-25 15:47:00+00:00 USGS 2012-04-25 10:47 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 5 9 9 A-1180039 **Second GCC bottle (SCH4433) is and... < 0.16 < 0.16 < 0.02 < 0.02
2012-05-17 13:40:00+00:00 USGS 2012-05-17 08:40 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 5 9 9 A-1390189 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-05-24 18:23:00+00:00 USGS 2012-05-24 13:23 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 8 9 J A-1500157 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-06-14 14:15:00+00:00 USGS 2012-06-14 09:15 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 5 9 9 A-1710114 **Second GCC bottle (sch. 4433) is a... < 0.16 < 0.16 < 0.02 < 0.02
2012-06-20 18:43:00+00:00 USGS 2012-06-20 13:43 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 7 9 J A-1740217 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-07-17 14:50:00+00:00 USGS 2012-07-17 09:50 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 5 9 9 A-2010133 **Second GCC bottle (sch. 4433) is a... < 0.16 < 0.16 < 0.02 < 0.02
2012-08-13 14:55:00+00:00 USGS 2012-08-13 09:55 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 9 9 9 A-2280252 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-09-04 13:45:00+00:00 USGS 2012-09-04 08:45 NaN NaN -0500 K USGS-WRD WS GR12NK00E ... NaN NaN 4 9 9 A-2500209 ***Second GCC bottle (sch4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-10-10 14:40:00+00:00 USGS 2012-10-10 09:40 NaN NaN -0500 K USGS-WRD WS GR13NK00E ... NaN NaN 4 9 9 A-2860068 ***Second GCC bottle (sch 4433) is a... < 0.16 < 0.16 < 0.02 < 0.02
2012-11-14 14:45:00+00:00 USGS 2012-11-14 08:45 NaN NaN -0600 K USGS-WRD WS GR13NK00E ... NaN NaN 4 9 9 A-3240067 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-12-20 16:50:00+00:00 USGS 2012-12-20 10:50 NaN NaN -0600 K USGS-WRD WS GR13NK00E ... NaN NaN 9 9 B A-3560065 ***Second GCC bottle (sch 4433) is a... < 0.16 0.01 bt < 0.02 < 0.02
2013-01-16 14:30:00+00:00 USGS 2013-01-16 08:30 NaN NaN -0600 K USGS-WRD WS GR13NK00E ... NaN NaN 9 9 B A-0180147 **Second GCC bottle (sch 4433) is an... < 0.16 M bt < 0.02 < 0.02
2013-04-27 15:40:00+00:00 USGS 2013-04-27 10:40 NaN NaN -0500 K USGS-WRD WS GR13NK00E ... NaN NaN 8 9 A A-1220123 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2014-04-21 18:00:00+00:00 USGS 2014-04-21 13:00 NaN NaN -0500 K USGSMNWC WS GR14NK00F ... NaN NaN 8 9 A NaN < 0.16 < 0.16 E 0.01 btc < 0.02
2014-07-09 14:30:00+00:00 USGS 2014-07-09 09:30 NaN NaN -0500 K USGSMNWC WS GR14NK00F ... NaN NaN 5 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2014-10-21 15:00:00+00:00 USGS 2014-10-21 10:00 NaN NaN -0500 K USGSMNWC WS GR15NK00F ... NaN NaN 4 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2015-04-28 17:45:00+00:00 USGS 2015-04-28 12:45 NaN NaN -0500 K USGSMNWC WS MN-00300 ... NaN NaN 9 9 9 L-1210024 Received April 30, 2015 < 0.16 < 0.16 < 0.02 < 0.02
2015-10-20 16:55:00+00:00 USGS 2015-10-20 11:55 NaN NaN -0500 K USGSMNWC WS MN-00300 ... NaN NaN 5 9 9 MM-44934A < 0.16 < 0.16 < 0.02 < 0.02
2016-02-02 15:45:00+00:00 USGS 2016-02-02 09:45 NaN NaN -0600 K USGSMNWC WS MN-00300 ... NaN NaN 9 9 B MM-45749A < 0.16 < 0.16 < 0.02 < 0.02
2016-06-08 15:35:00+00:00 USGS 2016-06-08 10:35 NaN NaN -0500 K USGSMNWC WS MN-00300 ... NaN NaN 5 9 9 MM-47133A < 0.16 < 0.16 < 0.02 < 0.02
2016-07-05 14:55:00+00:00 USGS 2016-07-05 09:55 NaN NaN -0500 K USGSMNWC WS MN-00300 ... NaN NaN 5 9 9 MM-47591A < 0.16 < 0.16 < 0.02 < 0.02
2016-11-15 17:05:00+00:00 USGS 2016-11-15 11:05 NaN NaN -0600 K USGSMNWC WS MN-00300 ... NaN NaN 9 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2017-02-01 17:05:00+00:00 USGS 2017-02-01 11:05 NaN NaN -0600 K USGSMNWC WS MN-00300 ... NaN NaN 9 9 B NaN < 0.16 < 0.16 < 0.02 < 0.02
2017-04-04 17:05:00+00:00 USGS 2017-04-04 12:05 NaN NaN -0500 K USGSMNWC WS MN-00300 ... NaN NaN 5 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2017-07-05 16:50:00+00:00 USGS 2017-07-05 11:50 NaN NaN -0500 K USGSMNWC WS MN-00300 ... NaN NaN 5 9 9 NaN < 0.16 0.01 bt < 0.02 < 0.02
2017-11-27 16:40:00+00:00 USGS 2017-11-27 10:40 NaN NaN -0600 K USGSMNWC WS MN-00300 ... NaN NaN 9 9 9 L-3330046 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
2018-02-06 14:45:00+00:00 USGS 2018-02-06 08:45 NaN NaN -0600 K USGSMNWC WS MN-00300 ... NaN NaN 9 9 B L-0380062 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
2018-05-01 16:05:00+00:00 USGS 2018-05-01 11:05 NaN NaN -0500 K USGSMNWC WS 00GQ41400 ... NaN NaN 5 9 9 L-1230062 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
2018-07-09 16:25:00+00:00 USGS 2018-07-09 11:25 NaN NaN -0500 K USGSMNWC WS 00GQ41400 ... NaN NaN 6 9 9 L-1920083 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
04024430 2014-04-30 18:40:00+00:00 USGS 2014-04-30 13:40 NaN NaN -0500 K USGS-WRD WS F6X7H ... NaN NaN 7 9 J NaN 0.10 n < 0.16 < 0.02 < 0.02
2014-06-10 13:50:00+00:00 USGS 2014-06-10 08:50 NaN NaN -0500 K USGS-WRD WS F6X7H ... NaN NaN 9 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2014-10-29 19:30:00+00:00 USGS 2014-10-29 14:30 NaN NaN -0500 K USGS-WRD WS GLRI TOX ... NaN NaN 9 9 9 NaN < 0.16 0.01 bt < 0.02 < 0.02
2014-11-12 19:30:00+00:00 USGS 2014-11-12 13:30 NaN NaN -0600 K USGS-WRD WS GLRI TOX ... NaN NaN 7 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02

38 rows × 21 columns

The following example is the same as the previous example but with multi index turned off (multi_index=False)

[10]:
site_ids = ['04024430', '04024000']
parameterCd = ['34247', '30234', '32104', '34220']
startDate = '2012-01-01'
endDate = ''
wq_data2 = nwis.get_qwdata(sites=site_ids, parameterCd=parameterCd,
                           start=startDate, end=endDate, multi_index=False)
print('Retrieved data for ' + str(len(wq_multi_site[0])) + ' samples.')
display(wq_data2[0])
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/nwis.py:193: UserWarning: WARNING: Starting in March 2024, the NWIS qw data endpoint is retiring and no longer receives updates. For more information, refer to https://waterdata.usgs.gov.nwis/qwdata and https://doi-usgs.github.io/dataRetrieval/articles/Status.html or email CompTools@usgs.gov.
  warnings.warn(
Retrieved data for 281 samples.
agency_cd site_no sample_dt sample_tm sample_end_dt sample_end_tm sample_start_time_datum_cd tm_datum_rlbty_cd coll_ent_cd medium_cd ... tu_id body_part_id hyd_cond_cd samp_type_cd hyd_event_cd sample_lab_cm_txt p30234 p32104 p34220 p34247
datetime
2012-01-25 14:40:00+00:00 USGS 04024000 2012-01-25 08:40 NaN NaN -0600 K USGS-WRD WS ... NaN NaN 4 9 B A-0270113 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-02-22 14:45:00+00:00 USGS 04024000 2012-02-22 08:45 NaN NaN -0600 K USGS-WRD WS ... NaN NaN 4 9 B A-0540032 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-03-12 13:55:00+00:00 USGS 04024000 2012-03-12 08:55 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 4 9 B A-0740087 ** Second GCC bottle (Sch 4433) is a... < 0.16 0.01 bt < 0.02 < 0.02
2012-03-27 13:55:00+00:00 USGS 04024000 2012-03-27 08:55 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 9 9 A A-0900013 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-04-17 14:20:00+00:00 USGS 04024000 2012-04-17 09:20 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 8 9 J A-1110047 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-04-25 15:47:00+00:00 USGS 04024000 2012-04-25 10:47 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 5 9 9 A-1180039 **Second GCC bottle (SCH4433) is and... < 0.16 < 0.16 < 0.02 < 0.02
2012-05-17 13:40:00+00:00 USGS 04024000 2012-05-17 08:40 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 5 9 9 A-1390189 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-05-24 18:23:00+00:00 USGS 04024000 2012-05-24 13:23 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 8 9 J A-1500157 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-06-14 14:15:00+00:00 USGS 04024000 2012-06-14 09:15 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 5 9 9 A-1710114 **Second GCC bottle (sch. 4433) is a... < 0.16 < 0.16 < 0.02 < 0.02
2012-06-20 18:43:00+00:00 USGS 04024000 2012-06-20 13:43 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 7 9 J A-1740217 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-07-17 14:50:00+00:00 USGS 04024000 2012-07-17 09:50 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 5 9 9 A-2010133 **Second GCC bottle (sch. 4433) is a... < 0.16 < 0.16 < 0.02 < 0.02
2012-08-13 14:55:00+00:00 USGS 04024000 2012-08-13 09:55 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 9 9 9 A-2280252 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-09-04 13:45:00+00:00 USGS 04024000 2012-09-04 08:45 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 4 9 9 A-2500209 ***Second GCC bottle (sch4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-10-10 14:40:00+00:00 USGS 04024000 2012-10-10 09:40 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 4 9 9 A-2860068 ***Second GCC bottle (sch 4433) is a... < 0.16 < 0.16 < 0.02 < 0.02
2012-11-14 14:45:00+00:00 USGS 04024000 2012-11-14 08:45 NaN NaN -0600 K USGS-WRD WS ... NaN NaN 4 9 9 A-3240067 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2012-12-20 16:50:00+00:00 USGS 04024000 2012-12-20 10:50 NaN NaN -0600 K USGS-WRD WS ... NaN NaN 9 9 B A-3560065 ***Second GCC bottle (sch 4433) is a... < 0.16 0.01 bt < 0.02 < 0.02
2013-01-16 14:30:00+00:00 USGS 04024000 2013-01-16 08:30 NaN NaN -0600 K USGS-WRD WS ... NaN NaN 9 9 B A-0180147 **Second GCC bottle (sch 4433) is an... < 0.16 M bt < 0.02 < 0.02
2013-04-27 15:40:00+00:00 USGS 04024000 2013-04-27 10:40 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 8 9 A A-1220123 **Second GCC bottle (sch 4433) is an... < 0.16 < 0.16 < 0.02 < 0.02
2014-04-21 18:00:00+00:00 USGS 04024000 2014-04-21 13:00 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 8 9 A NaN < 0.16 < 0.16 E 0.01 btc < 0.02
2014-04-30 18:40:00+00:00 USGS 04024430 2014-04-30 13:40 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 7 9 J NaN 0.10 n < 0.16 < 0.02 < 0.02
2014-06-10 13:50:00+00:00 USGS 04024430 2014-06-10 08:50 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 9 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2014-07-09 14:30:00+00:00 USGS 04024000 2014-07-09 09:30 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2014-10-21 15:00:00+00:00 USGS 04024000 2014-10-21 10:00 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 4 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2014-10-29 19:30:00+00:00 USGS 04024430 2014-10-29 14:30 NaN NaN -0500 K USGS-WRD WS ... NaN NaN 9 9 9 NaN < 0.16 0.01 bt < 0.02 < 0.02
2014-11-12 19:30:00+00:00 USGS 04024430 2014-11-12 13:30 NaN NaN -0600 K USGS-WRD WS ... NaN NaN 7 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2015-04-28 17:45:00+00:00 USGS 04024000 2015-04-28 12:45 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 9 9 9 L-1210024 Received April 30, 2015 < 0.16 < 0.16 < 0.02 < 0.02
2015-10-20 16:55:00+00:00 USGS 04024000 2015-10-20 11:55 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 MM-44934A < 0.16 < 0.16 < 0.02 < 0.02
2016-02-02 15:45:00+00:00 USGS 04024000 2016-02-02 09:45 NaN NaN -0600 K USGSMNWC WS ... NaN NaN 9 9 B MM-45749A < 0.16 < 0.16 < 0.02 < 0.02
2016-06-08 15:35:00+00:00 USGS 04024000 2016-06-08 10:35 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 MM-47133A < 0.16 < 0.16 < 0.02 < 0.02
2016-07-05 14:55:00+00:00 USGS 04024000 2016-07-05 09:55 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 MM-47591A < 0.16 < 0.16 < 0.02 < 0.02
2016-11-15 17:05:00+00:00 USGS 04024000 2016-11-15 11:05 NaN NaN -0600 K USGSMNWC WS ... NaN NaN 9 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2017-02-01 17:05:00+00:00 USGS 04024000 2017-02-01 11:05 NaN NaN -0600 K USGSMNWC WS ... NaN NaN 9 9 B NaN < 0.16 < 0.16 < 0.02 < 0.02
2017-04-04 17:05:00+00:00 USGS 04024000 2017-04-04 12:05 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 NaN < 0.16 < 0.16 < 0.02 < 0.02
2017-07-05 16:50:00+00:00 USGS 04024000 2017-07-05 11:50 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 NaN < 0.16 0.01 bt < 0.02 < 0.02
2017-11-27 16:40:00+00:00 USGS 04024000 2017-11-27 10:40 NaN NaN -0600 K USGSMNWC WS ... NaN NaN 9 9 9 L-3330046 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
2018-02-06 14:45:00+00:00 USGS 04024000 2018-02-06 08:45 NaN NaN -0600 K USGSMNWC WS ... NaN NaN 9 9 B L-0380062 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
2018-05-01 16:05:00+00:00 USGS 04024000 2018-05-01 11:05 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 5 9 9 L-1230062 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02
2018-07-09 16:25:00+00:00 USGS 04024000 2018-07-09 11:25 NaN NaN -0500 K USGSMNWC WS ... NaN NaN 6 9 9 L-1920083 Numerical result and or metadata rev... < 0.16 < 0.16 < 0.02 < 0.02

38 rows × 22 columns

Example 4: Retrieve water quality sample data for one site in serial format

Each row in the resulting table represents a single observation of a single parameters. Each sample may be analyzed for multiple parameters and so a single water quality sample can result in multiple rows in serial format.

[11]:
siteID = '10109000'
wq_data = nwis.get_qwdata(sites=siteID, wide_format=False)
print('Retrieved data for ' + str(len(wq_data[0])) + ' sample results.')
display(wq_data[0])
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/nwis.py:193: UserWarning: WARNING: Starting in March 2024, the NWIS qw data endpoint is retiring and no longer receives updates. For more information, refer to https://waterdata.usgs.gov.nwis/qwdata and https://doi-usgs.github.io/dataRetrieval/articles/Status.html or email CompTools@usgs.gov.
  warnings.warn(
Retrieved data for 2465 sample results.
/home/runner/.local/lib/python3.10/site-packages/dataretrieval/utils.py:90: UserWarning: Warning: 36 incomplete dates found, consider setting datetime_index to False.
  warnings.warn(
agency_cd site_no sample_dt sample_tm sample_end_dt sample_end_tm sample_start_time_datum_cd tm_datum_rlbty_cd coll_ent_cd medium_cd ... dqi_cd rpt_lev_va rpt_lev_cd lab_std_va prep_set_no prep_dt anl_set_no anl_dt result_lab_cm_tx anl_ent_cd
datetime
1967-09-13 13:35:00+00:00 USGS 10109000 1967-09-13 07:35 NaN NaN -0600 T NaN WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
1967-09-13 13:35:00+00:00 USGS 10109000 1967-09-13 07:35 NaN NaN -0600 T NaN WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
1967-09-13 13:35:00+00:00 USGS 10109000 1967-09-13 07:35 NaN NaN -0600 T NaN WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
1967-09-13 13:35:00+00:00 USGS 10109000 1967-09-13 07:35 NaN NaN -0600 T NaN WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
1967-09-13 13:35:00+00:00 USGS 10109000 1967-09-13 07:35 NaN NaN -0600 T NaN WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
NaT USGS 10109000 1989-10-05 NaN NaN NaN -0600 T USGS-WRD WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-10-05 NaN NaN NaN -0600 T USGS-WRD WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-10-05 NaN NaN NaN -0600 T USGS-WRD WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-10-05 NaN NaN NaN -0600 T USGS-WRD WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaT USGS 10109000 1989-10-05 NaN NaN NaN -0600 T USGS-WRD WS ... A NaN NaN NaN NaN NaN NaN NaN NaN NaN

2465 rows × 33 columns