SEBASTIAN
SEBASTIAN

Reputation: 75

Pandas TypeError: Object of type DataFrame is not JSON serializable

I want to create a pandas DataFrame from a query_set.QuerySet object but when I go for:

df = pd.DataFrame.from_dict(res)

res being the query set, I get the following error:

TypeError: Object of type DataFrame is not JSON serializable. 

What can I do to fix it? Thanks in advance!

Upvotes: 0

Views: 2121

Answers (1)

icaine
icaine

Reputation: 444

Assuming it's Django's QuerySet you can use the following code:

df = pd.DataFrame.from_dict(res.values())

queryset.values() returns list of dicts.

You can find more information at this link.

Upvotes: 1

Related Questions