Reputation: 63619
When reading the pandas doc on pandas.Series
, it states
A Series is like a fixed-size dict in that you can get and set values by index label:
http://pandas.pydata.org/pandas-docs/version/0.13.1/dsintro.html#series-is-dict-like
Question: What does it mean by pandas.Series being a fixed-size dict
, and if its not like a fixed size dict, what can it do?
Upvotes: 2
Views: 632
Reputation: 375415
Like a fixed-sized dict, you can get and set (already existing) keys efficiently.
What you cannot do (efficiently) is add an element. Though you can do it:
In [11]: s
Out[11]:
a -1.344
b 0.845
c 1.076
d -0.109
e 12.000
dtype: float64
In [12]: s["f"] = 3.14 # works but slow (copies all the data)
In [13]: s
Out[13]:
a -1.344
b 0.845
c 1.076
d -0.109
e 12.000
f 3.140
dtype: float64
As this creates a new Series (i.e. via creating copy the old).
What Series (and general numpy and pandas objects allow efficient aggregations e.g. sums and groupby operations. Where using a python dict similar aggregations would be very slow.
A hand-wavy reason for this is that it's mostly due to the way that data can be stored in memory (contiguously and with known types) rather than with python objects whether they are pointers to a pointer for the type and pointer for the data (this misdirection means things are slower)...
Pandas also comes with a lot of efficiently written functions, and a neat API, so you don't have to rewrite all the functionality you need yourself...
Upvotes: 2