Skip to content
Advertisement

Converting dict to DataFrame gives too many rows

I am trying to convert a dict to Pandas DataFrame as the following:

JavaScript

And when I print out the DataFrame, I see the following output:

JavaScript

enter image description here

I expect to see 1 row only in the DataFrame but it gives 5. And I cannot understand why. What am I doing wrong here?

Advertisement

Answer

You’re not doing anything wrong. Since tags is a list, Pandas broadcasts all other fields to same size as tags and make a dataframe. You can do:

JavaScript

Or wrap your dict around [] indicating it’s a row (record orient):

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement