Skip to content

Instantly share code, notes, and snippets.

@nickynicolson
Created March 24, 2020 15:26
Show Gist options
  • Save nickynicolson/9858c266bfcb5157496fdba3bf519b1b to your computer and use it in GitHub Desktop.
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
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