2

DataFrame constructor error when load data from JSON

I got the following error when load JSON data into dataframe by df = pd.DataFrame(data)

DataFrame constructor not properly called!

/usr/local/lib/python2.7/site-packages/pandas/core/frame.pyc in __init__(self, data, index, columns, dtype, copy)
    284                                          copy=False)
    285             else:
--> 286                 raise PandasError('DataFrame constructor not properly called!')
    287 
    288         NDFrame.__init__(self, mgr, fastpath=True)

PandasError: DataFrame constructor not properly called!

Is think I read the data into dataframe on a wrong way,

What's the correct way to read it into dataframe.

data

https://gist.github.com/poc7667/0e4cded9920f78f2de1c

2 Answers 2

1

The problem is that in lines 110 and 111 you have not escaped the backslash. When this is done

pd.read_json('data.json')

works just fine

Sign up to request clarification or add additional context in comments.

Comments

0

This won't work in general, but it will in this case because your JSON data can be mapped to a DataFrame (i.e. it is a dictionary where each item holds the same number of values and has no further nesting).

It uses dictionary comprehension and iterates over the items in the data.

df = pd.DataFrame({k: v for k, v in data.iteritems()})

1 Comment

You didn't mention if your JSON data was a dictionary or a serialized string. If the latter, then the pd.read_json() method mentioned by Woody should work just fine.

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.