Reputation: 3125
Why doesn't Pandas build DataFrames directly from lists? Why was such a thing as a series created in the first place?
Or: If the data in a DataFrame is actually stored in memory as a collection of Series, why not just use a collection of lists?
Yet another way to ask the same question: what's the purpose of Series over lists?
Upvotes: 1
Views: 952
Reputation: 3689
This isn't going to be a very complete answer, but hopefully is an intuitive "general" answer.
Pandas doesn't use a list as the "core" unit that makes up a DataFrame
because Series
objects make assumptions that lists do not. A list in python makes very little assumptions about what is inside, it could be pretty much anything, which makes it great as a core component of python.
However, if you want to build a more specialized package that gives you extra functionality liked Pandas
, then you want to create your own "core" data object and start building extra functionality on top of that. Compared with lists, you can do a lot more with a custom Series
object (as witnessed by pulling a single column from a DataFrame
and seeing what methods are available to the output).
Upvotes: 2