YOUR_API_KEY
stands for your Alta Data API key.PRODUCT_CODE
is a code created to use the Data Product with API.
You can find the product code in the API section of the data product page.
Firstly import library with the code below.
from altadata.altadata import *
You can get the entire data with the code below. ~altadata.AltaDataAPI.get_data
returns list of dict by default.
client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(PRODUCT_CODE).load()
If dataframe_functionality parameter is True ~altadata.AltaDataAPI.get_data
returns pandas dataframe.
Note:
This functionality requires pandas (v0.23 or above) to work.
client = AltaDataAPI(api_key=YOUR_API_KEY, dataframe_functionality=True)
data = client.get_data(PRODUCT_CODE).load()
You can get data with using various conditions.
The columns you can apply these filter operations to are limited to the filtered columns.
You can find the filtered columns in the data section of the data product page.
product_code = "co_10_jhucs_03"
client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code = product_code)\
.equal(condition_column="province_state", condition_value="Montana")\
.load()
product_code = "co_10_jhucs_03"
client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
.condition_in(condition_column="province_state", condition_value=["Montana", "Utah"])\
.load()
product_code = "co_10_jhucs_03"
client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
.condition_not_in(condition_column="province_state", condition_value=["Montana", "Utah"])\
.load()
You can sort data based on a specific column and method.
product_code = "co_10_jhucs_03"
client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
.sort(order_column="mortality_rate", order_method="desc")\
.load()
You can get only selected columns.
product_code = "co_10_jhucs_03"
client = AltaDataAPI(YOUR_API_KEY)
data = client.get_data(product_code)\
.select(selected_column=["reported_date", "province_state", "mortality_rate"])\
.load()
You can limit data.
product_code = "co_10_jhucs_03" client = AltaDataAPI(YOUR_API_KEY) data = client.get_data(product_code, limit=20).load()
You can use multiple condition at same time.
product_code = "co_10_jhucs_03" client = AltaDataAPI(YOUR_API_KEY) data = client.get_data(product_code, limit=100)\ .condition_in(condition_column="province_state", condition_value=["Montana", "Utah"])\ .sort(order_column="mortality_rate", order_method="desc")\ .select(selected_column=["reported_date", "province_state", "mortality_rate"])\ .load()