I have a json array f below format

    'Address': 'xxx',
    'Latitude': 28. xxx,
    'Longitude': 77. xxx,
    'reached': False
}, {
    'Address': 'yyy',
    'Latitude': 18. yyy,
    'Longitude': 73. yyy,
    'reached': False

i want to convert into dataframe. if the column name is same it should have (Address_0, Address_1 etc) and should be side by side, not below. How can i do this?

  • $\begingroup$ Did you tried, what happens, what error shown? $\endgroup$ – Venkatesh Gandi May 3 '20 at 13:05

Have you tried using the pandas.read_json method? (documentation)

And it looks like your json is structured like 'records' so use

pd.read_json(_, orient='records')
  • $\begingroup$ im getting error ValueError: Invalid file path or buffer object type: <class 'list'> $\endgroup$ – phoenix May 3 '20 at 13:15
  • $\begingroup$ Did you change the underscore to the actual path? pd.read_json(PATH_HERE, orient='records') $\endgroup$ – A Kareem May 3 '20 at 13:29
  • $\begingroup$ The error you are getting is caused by the fact that the variable you are inputting (i.e. your data) is of type list, not a json string. $\endgroup$ – Oxbowerce May 3 '20 at 13:32
  • $\begingroup$ i have already read the input and parsed it. the above records are inside transit.. so what I have done is eachData['transits']=transitArray.. so above records are in transitarray.. so what should I do next? $\endgroup$ – phoenix May 3 '20 at 13:35
  • $\begingroup$ Where are you getting your input data from and how are you parsing it? The issue is coming from the fact that your data is a list instead of a string. $\endgroup$ – Oxbowerce May 3 '20 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.