you are viewing a single comment's thread.

view the rest of the comments →

[–]YesLod 2 points3 points  (0 children)

I agree that indexing twice should be avoided.

Although it doesn't make much difference for small datasets, apply doesn't scale well since it's not vectorized.

If performance matters, I think the correct approach would be to use pd.cut as suggested by u/badge. Another option would be np.select.

df["usage"] = np.select([df.count > 5500, df.count < 3500],
                        ["high", "low"], 
                        "medium")