Created
March 24, 2020 15:26
-
-
Save nickynicolson/9858c266bfcb5157496fdba3bf519b1b to your computer and use it in GitHub Desktop.
Use the Index Herbariorum API to download data into a simple pandas dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from pandas.io.json import json_normalize | |
import requests | |
# IH API documented here: https://github.com/nybgvh/IH-API/wiki | |
url='http://sweetgum.nybg.org/science/api/v1/institutions' | |
def main(): | |
response = requests.get(url) | |
results = response.json() | |
# The JSON format record for an IH record has nested sections - the | |
# call to json_normalize flattens these: | |
df = pd.DataFrame(json_normalize(results['data'])) | |
# Now have a pandas dataframe holding all the IH data: | |
print(df[['irn','organization','location.lat','location.lon']].head(n=50)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment