Skip to content

Comment on What would it take to recreate dplyr in Python? (2020)parent

Comments

In my own experience my struggles come from not taking the time to properly understand indexes. When starting out many things are intuitive so it feels documentation isn’t that necessary. But then you hit a wall and things don’t work correctly. At this point I would just try everything brute force or search stack overflow until I got it to work so I could move on with other things. But it was just a quick fix. Once I took a few hours reading and trying examples to understand how the index works things made sense.

When you start with simple data frames it feels dict-like and very pythonic —- zero learning curve. But then multi-indexes are lists of tuples and things get tricky. It’s also important that data frames always have an index whether you realize it or not, the default being a RangeIndex.

This is why the “to_csv” bites people, there’s a numerical index. Once an index is set you no longer have to say “index=False”.

With the default RangeIndex “df.loc[0]” and “df.iloc[0]” will give the same result because the first record has both the position 0 and index value of 0. Once a “meaningful” index is set you need to start referring to it by value rather than position. This makes it much easier to manipulate data, for me at least.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.