Reputation: 394
I have a requirement to keep data in key value pairs. I search and found 2 ways in python:
default data structure dictionary.
x = {'key':value}
value = x['key']
series of pandas data structure.
x = pandas.Series({'key':value})
value = x.key
I want to know the difference between this two apart from syntax.
Upvotes: 18
Views: 32758
Reputation: 415
There are 2 important differences.
1) Syntax and associated methods Allows for complex data manipulation in Panda series that would be difficult to achieve using a standard dictionary.
2) Order Standard python dictionaries are unordered sets; values can only be accessed by keys. Data in Panda series can be accessed by keys BUT can also be accessed with a numeric index because they are ordered.
In some ways, Panda series combine the best worlds of standard lists and standard dictionaries in python, but then top it off with some great data manipulation methods.
Upvotes: 1
Reputation: 23134
Always read the docs first
But since you asked:
key: value
pairs and offer some built-in methods
to manipulate your data, which you can read on the docs (here is a
good summary to jump start your reading process).array-like, dict, or scalar
values and are one of numpy's (a scientific computing python
library) built-in data structures. So it is not just a syntax difference to say the least.
If you only need to store some key:value
pairs, your best and more elegant solution is to use the default dictionary. If you need to make some complex data manipulation on the stored data, then consider using panda's series.
Upvotes: 24