Skip to content

Instantly share code, notes, and snippets.

@niconoe
Last active June 25, 2021 08:48
Show Gist options
  • Save niconoe/1ca7f21857ad63eb68d25ecddfcd8f79 to your computer and use it in GitHub Desktop.
Save niconoe/1ca7f21857ad63eb68d25ecddfcd8f79 to your computer and use it in GitHub Desktop.
import pandas as pd
import json
source_df = pd.read_csv('./data_agouti.csv')
def pd_row_to_dict(row):
return {
'taxon_id': row['taxon_id'],
'scientific_name': row['scientific_name'],
'vernacular_names': [
{
'name': row['name_en'],
'language': 'en'
},
{
'name': row['name_nl'],
'language': 'nl'
}
]
}
result = [pd_row_to_dict(row) for _, row in source_df.iterrows()]
print(json.dumps(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment