Stephen
Stephen

Reputation: 467

orderedDict vs pandas series

Still new to this, sorry if I ask something really stupid. What are the differences between a Python ordered dictionary and a pandas series?

The only difference I could think of is that an orderedDict can have nested dictionaries within the data. Is that all? Is that even true?

Would there be a performance difference between using one vs the other?

My project is a sales forecast, most of the data will be something like: {Week 1 : 400 units, Week 2 : 550 units}... Perhaps an ordered dictionary would be redundant since input order is irrelevant compared to Week#?

Again I apologize if my question is stupid, I am just trying to be thorough as I learn.

Thank you!

-Stephen

Upvotes: 6

Views: 1349

Answers (2)

PlagTag
PlagTag

Reputation: 6429

Ordered dict is implemented as part of the python collections lib. These collection are very fast containers for specific use cases. If you would be looking for only dictionary related functionality (like order in this case) i would go for that. While you say you are going to do more deep analysis in an area where pandas is really made for (eg plotting, filling missing values). So i would recommend you going for pandas.Series.

Upvotes: 1

Stefan
Stefan

Reputation: 42875

Most importantly, pd.Series is part of the pandas library so it comes with a lot of added functionality - see attributes and methods as you scroll down the pd.Series docs. This compares to OrderDict: docs.

For your use case, using pd.Series or pd.DataFrame (which could be a way of using nested dictionaries as it has an index and multiple columns) seem quite appropriate. If you take a look at the pandas docs, you'll also find quite comprehensive time series functionality that should come in handy for a project around weekly sales forecasts.

Since pandas is built on numpy, the specialized scientific computing package, performance is quite good.

Upvotes: 2

Related Questions