From the course: Data Pipeline Automation with GitHub Actions Using R and Python
Querying data with R and Python - GitHub Tutorial
From the course: Data Pipeline Automation with GitHub Actions Using R and Python
Querying data with R and Python
- [Instructor] So far in the previous videos, we viewed the API functionality and saw how to set and send a get request via the browser. We'll dedicate the rest of this chapter to learn and practice how to query data from the API using R and Python. To pull data with R we will use the EIA API library that provides a set of functions to query data from the current version of the API V2. The package is available on CRAN and we will use the current version 0.1.2. For Python, currently, there is no stable library that supports the V2 of the API. Therefore, to be consistent, I created a set of Python functions aligned with the ones available in the EIA API library, which we'll use to pull the data from the API with Python. Throughout this course, we will use the following three functions, which are available both in R and Python to pull data from the API. First, the EIA underscore metadata, which as its name implies returns metadata. In the coming example, we will see how to use the function output to set the get request parameters. Next is the EIA underscore get function, which enable us to send get request to the API. The function retains time series data. As we previously saw the API is a cup of 5,000 observation limitation per get request. This might be challenging when pulling hourly data, as we're going to do heavily in this course. This is where the failed and last function. The EIA underscore backfill function comes in handy, enabling us to pull observation per request beyond the API limitation. On the backend the function splits the request into a sequence of smaller requests and send them to the API using the AI get function, it then appends the return outputs into one table. Throughout the course, we will mainly use the EIA backfill and the EIA metadata functions. Moving forward, we'll have coding demos in both Python and R, you can choose to continue with either one of the languages and skip the other or watch both languages.
Contents
-
-
-
EIA API2m 47s
-
Setting an environment variable3m 22s
-
The EIA API dashboard4m 10s
-
GET request structure5m 41s
-
Querying the data via the browser4m 4s
-
Querying data with R and Python2m 50s
-
Pulling metadata from API with R3m 5s
-
Sending a simple GET request with R5m 19s
-
API limitations with R4m 43s
-
Handling a large data request with R4m 27s
-
Pulling metadata from API with Python3m 47s
-
Sending a simple GET request with Python4m 44s
-
API limitations with Python3m 54s
-
Handling a large data request with Python3m 10s
-
Challenge: Query the API1m 2s
-
Solution: Query the API with R7m 28s
-
Solution: Query the API with Python7m 45s
-
-
-
-
-