1

I've come across something that while looking at how to normalize data on datacamp.com

In one of the exercises it was said that to normalize a dataframe df one should do like this

normalized_df = df / df.mean()

My question is: why does this work? Why does Pandas know here to divide columnwise?

Thanks

Edit: This post Dataframe divide series on pandas does not answer the question I am posting. I merely states what to do. I want to know why it works.

Trace
  • 53
  • 5
  • 2
    All the information you need is in that post. TL;DR The result of `df.mean()` produces a `pandas.Series` object whose index matches the `columns` of `df`. When dividing `df / df.mean()`, Pandas sees the index of `df.mean()` and matches it with the `columns` of `df` by default. That is how it knows. – piRSquared Apr 27 '20 at 19:42
  • it works because of df.mean(axis=0) which is the default value. – Mo Huss Apr 27 '20 at 19:43
  • Thanks, piRSquared! – Trace Apr 27 '20 at 19:46

0 Answers0