<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Retrieving Data from the TataAQ Server
Data can be accessed using the API and this (py-tata) python library. It can also be retrieved in many other ways using the API itself; however, that isn't documented yet and probably won't be in the foreseable future.
To retrieve data, you must have an API key which can be accessed through your account on the TataAQ website. Here, I will show how to retrieve data for one of the instruments and export it to an external file format (i.e. csv or feather).
Initialize the API Wrapper
Step1:  Import Things
We are going to import some other libraries that are handy for working with data
Step2:  Retrieve Information about a Device
To retrieve information about a device, you need to know it's Device ID. This can be found by looking at the website. 
The device API endpoint returns a request object. you can learn more about them by looking at the python requests library. All you really need to know will be shown below.
Example
Step3:  Access the status of the previous request
Step4:  Access the header information
Step5:  Access the json information (data)
Step6:  Retrieve the Actual Data
First, we are going to retrieve the data and return in JSON format.
Step7:  We can get the actual data by accesing the "data" key in the resp.json() dictionary
Step8:  We can also add keywords to our request. The most useful ones are the following
Step9:  Utilizing the Magical DataFrame
We can also retrieve the data and return as a pandas DataFrame, which is way more useful. When you add the dataframe=True argument to the request, it will return the meta information as a dictionary, and the data as a pandas DataFrame.
Let's see how this works
Step10:  Let's take a look at our data now
Step11:  Let's get all data from the EBAM for the year 2017
Step12:  Export Data
Once in a DataFrame, it is super easy to export and save your data. I personally recommend using feather, as it is much faster than anything else, and is language agnostic. There are libraries built for R, Python, and Julia, making it easy to analyze your data in any programming language (OSS only, obviously).
To export the dataframe to feather, do the following
<ASSISTANT_TASK:>
Python Code:
import tataaq
YOUR_API_KEY_HERE = ""
api = tataaq.TataAQ(apikey=YOUR_API_KEY_HERE)
# Ping the server to see if we have valid auth credentials
resp = api.ping()
print (resp.status_code)
Explanation: Retrieving Data from the TataAQ Server
Data can be accessed using the API and this (py-tata) python library. It can also be retrieved in many other ways using the API itself; however, that isn't documented yet and probably won't be in the foreseable future.
To retrieve data, you must have an API key which can be accessed through your account on the TataAQ website. Here, I will show how to retrieve data for one of the instruments and export it to an external file format (i.e. csv or feather).
Initialize the API Wrapper
End of explanation
import pandas as pd
import feather
Explanation: Import Things
We are going to import some other libraries that are handy for working with data
End of explanation
# Request decice information for EBAM001
resp = api.device("EBAM001")
Explanation: Retrieve Information about a Device
To retrieve information about a device, you need to know it's Device ID. This can be found by looking at the website. 
The device API endpoint returns a request object. you can learn more about them by looking at the python requests library. All you really need to know will be shown below.
Example: grab information for device_id="EBAM001"
End of explanation
resp.status_code
Explanation: Access the status of the previous request
End of explanation
resp.headers
Explanation: Access the header information
End of explanation
resp.json()
Explanation: Access the json information (data)
End of explanation
# Request the data
resp = api.data("EBAM001")
# Print the  meta information
resp.json()['meta']
Explanation: Retrieve the Actual Data
First, we are going to retrieve the data and return in JSON format.
End of explanation
# print the 0 row
resp.json()['data'][0]
Explanation: We can get the actual data by accesing the "data" key in the resp.json() dictionary:
End of explanation
# return data after 2017-01-01
resp = api.data("EBAM001", per_page=100, filter="timestamp,gt,2017-01-01")
resp.json()['meta']
Explanation: We can also add keywords to our request. The most useful ones are the following:
per_page: alter the number of data points sent per page (default is 50)
page: iterate over all pages
filter: complex keyword that is very powerful. Examples shown below...
The filter keyword allows you to select by any column in the database. The most useful ones are querying over certain points in time. For example, if we wanted to return all data for EBAM001 after 2017-01-01, we would use the filter keyword as follows:
filter="timestamp,gt,2017-01-01"
We can also join multiple filter arguments together by seperating using a semicolon. For example, to return all data during the month of January 2017:
filter="timestamp,gt,2017-01-01;timestamp,lt,2017-02-01"
See below for working examples
End of explanation
meta, df = api.data("EBAM001", dataframe=True)
meta
Explanation: Utilizing the Magical DataFrame
We can also retrieve the data and return as a pandas DataFrame, which is way more useful. When you add the dataframe=True argument to the request, it will return the meta information as a dictionary, and the data as a pandas DataFrame.
Let's see how this works:
End of explanation
df.info()
Explanation: Let's take a look at our data now:
End of explanation
meta, df = api.data("EBAM001", per_page=10000, filter="timestamp,gt,2017-01-01", dataframe=True)
df.index = df['timestamp_local']
df.info()
# Delete a couple of columns so we can easily peak at the data
del df['instrument']
del df['timestamp']
df.head()
Explanation: Let's get all data from the EBAM for the year 2017
End of explanation
%time feather.write_dataframe(df, "EBAM001_2017_data.feather")
Explanation: Export Data
Once in a DataFrame, it is super easy to export and save your data. I personally recommend using feather, as it is much faster than anything else, and is language agnostic. There are libraries built for R, Python, and Julia, making it easy to analyze your data in any programming language (OSS only, obviously).
To export the dataframe to feather, do the following:
End of explanation
<END_TASK>