1

I'm trying to get an API call and save it as a dataframe. problem is that I need the data from the 'result' column. Didn't succeed to do that.

I'm basically just trying to save the API call as a csv file in order to work with it.

P.S when I do this with a "JSON to CSV converter" from the web it does it as I wish. (example: https://konklone.io/json/)

import requests
import pandas as pd
import json

res = requests.get("http://api.etherscan.io/api?module=account&action=txlist&
address=0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a&startblock=0&
endblock=99999999&sort=asc&apikey=YourApiKeyToken")

j = res.json()

j

df = pd.DataFrame(j)

df.head()

output example picture

1
  • good question, had the same issue Commented Apr 1, 2018 at 12:27

2 Answers 2

1

Try this

import requests
import pandas as pd
import json

res = requests.get("http://api.etherscan.io/api?module=account&action=txlist&address=0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken")

j = res.json()

# print(j)
filename ="temp.csv"
df = pd.DataFrame(j['result'])

print(df.head())
df.to_csv(filename)
Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you need.

df = pd.DataFrame(j["result"])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.