Posts

Showing posts from July, 2024

Pandas for Data Analysis: How to get Data from APIs

Image
It is much easier to create Data Frame objects from data we have from files such as csv, excel, list or JSON , but how do we obtain data from online sources such as APIs ? That is what we will learn from this short blog. Requirements We need “requests” and “pandas” packages to pull data from APIs sources. The requests package will be used to make API request while pandas is used to create Data Frame. On our Jupiter notebook, we add the following imports To test the aforementioned imports and how it pulls data from API source, we will request data from the USGS API. These are data recorded every day that relates to earthquake. We will pull data for the last 30 days up to yesterday. As such, we’ll need datetime package. Thus, all imports are as follows: Now that we’ve got all the imports ready, we can start pulling data from USGS API. With requests package, we will be able to make GET request to the USGSAPI and obtain JSON payload. The data we are trying to obtain were record