Skip to content

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

Comments

yea I know what you mean. The main use I have found is something like. Say you have a price per company_id and per transaction_id. Now you have some function, which for the sake of it, takes it to an exponent.

i used to write a lot of functions which went like this:

  def convert_price(price_frame:pd.DataFrame) -> pd.DataFrame:
      price_frame["new_price"] = np.exp(price_frame)
      return price_frame
and i came back to these functions, and i was always like. hmm what needs to be in the price frame. which columns etc. Also it mutates the state of the data frame

while i now write functions like

  def convert_price(price:pd.Series) -> pd.Series:
      return np.exp(price)
However what is good as well you can treat the series as a single dimensional array and do operations on it. Its not a perfect example since im not using the ids haha but you might see what i mean :D
AboutSource Built by g1lg1l

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