\n",
" \n",
"► If the above throws an error, can you debug it? HINT: the `geo` tag indicates whether coordinate info exist for the record...\n",
"
\n",
" \n",
"#Loop thorough each observation and print the lat and long values\n",
"for observation in data['data']:\n",
" if(observation['geo'] == 'Yes'):\n",
" print (observation['decimalLatitude'],observation['decimalLongitude'])\n",
"
\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Loop thorough each observation and print the lat and long values\n",
"for observation in data['data']:\n",
" if(observation['geo'] == 'Yes'):\n",
" print (observation['decimalLatitude'],observation['decimalLongitude'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using Pandas to streamline the process...\n",
"Pandas can create a dataframe directly from dictionary values. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"df = pd.DataFrame(data['data'])\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So now we can use our Panda's know-how to do some nifty analyses, including subsetting records for a specific provider.\n",
"* First we'll get a list of unique providers found in the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Generate a list of providers\n",
"df.provider.unique()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Now, we'll subset the rows that include that provider..."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"df.query(\"provider == 'iNaturalist.org'\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.dtypes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise:\n",
"* Extract the first 500 red wolf (*\"Canis rufus\"*) records from the BISON API. \n",
"* Can you create a table listing the records collected by the `University of Kansas Biodiversity Institute`?\n",
"* *Challenge*: Can you create a table listing all the records collected in North Carolina?"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}