Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a valid JSON from a dataframe #51

Closed
kovar-ursa opened this issue Nov 2, 2021 · 1 comment
Closed

Creating a valid JSON from a dataframe #51

kovar-ursa opened this issue Nov 2, 2021 · 1 comment

Comments

@kovar-ursa
Copy link

I have a pandas dataframe with 'latitude' and 'longitude' columns in it. I'd like to convert this into an appropriate JSON payload for the POST API using the Python requests library. Try as I might, I keep getting an "invalid JSON" error message.

Does anyone have example code for doing this?

Thank you.

@kovar-ursa
Copy link
Author

temp = df[['Latitude', 'Longitude']]
temp = temp.rename(columns={"Latitude": "latitude", "Longitude": "longitude"})
temp = temp.head(100)
result = temp.to_json(orient="records")
parsed = json.loads(result)
input_json = {"locations": parsed }
response = requests.post('https://api.open-elevation.com/api/v1/lookup', json = input_json)

This worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant