-3

I have a code like this,

def myfunction(json_dict):
     mylistsize = len((list(json_normalize(json_dict,'data')['title'])))-1
     print(mylistsize)
     data = [c for c in json_dict['data']][0]#This line when it is 0 or 1 or 2 works for me.
     df = pd.DataFrame()
     data_paragraphs = data['paragraphs']

But when I change it to include all the elements of my array, to something like this -

data = [c for c in json_dict['data']][0:mylistsize]

It gives me an error on this line - data_paragraphs = data['paragraphs']

Kindly help me with this.

  • can you show the full traceback of the error? – David Zemens May 29 '19 at 15:43
  • 1
    data is a list not a pandas DataFrame. – iamchoosinganame May 29 '19 at 15:44
  • What is `json_dict` and `json_normalize` function? – Devesh Kumar Singh May 29 '19 at 15:48
  • I answered, but the question shows little or no research. The error message, which contained the solution, was probably not even really read. It says the item was a list. If you think the item is a DataFrame or dict, your *very first* job is to investigate why you're getting the type that you're getting. Computers are really good at that. You, a human, are not. Ergo, your job is to find out what you have missed that the computer hasn't. `print(type(questionable_thing))` is your friend. As is `print(questionable_thing)`. Close in on the offending line with print statments. *Then* ask. Maybe. – Mike May 29 '19 at 15:59

1 Answers1

2

data is a list, from data = [c for c in json_dict['data']][0:mylistsize]. You access values in it like data[0]. To access json inside an item in the list, you do data[0]['paragraphs'].

Mike
  • 828
  • 8
  • 21