Data acquisition
Let's get our first set of IoT data.
You will get started by consuming an environmental API provided by a public community. The API consists of multiple endpoints, and you will start by consuming the temperature data. The data is in 10-minute intervals and limited historical data is available.
You will use requests to download the last 5 records.
Since the endpoint provides json encoded data, you can use .json() on the response object to get a python object (in this case a list).
Then you convert the list to a pandas DataFrame to be able to easily work with the data.
The constant URL to consume data from has been defined for you.
Please note that this URL is different from the URL used in the video.
Este exercício faz parte do curso
Analyzing IoT Data in Python
Instruções do exercício
- Import
requestsandpandasaspd. - Download data from
URLusing requests and store the result inres. - Convert the JSON-encoded result
resinto a python object and store the result indata_temp. - Convert
data_tempinto a pandas DataFramedf_temp.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Imports
____
____
# Download data from URL
res = ____
# Convert the result
data_temp = ____
print(data_temp)
# Convert json data to DataFrame
df_temp = pd.____(____)
print(df_temp.head())