Skip to content
Advertisement

Find the median of a column based on criteria within dataframe and insert this as a new column

I’m trying to look in a dataframe, and find the median of data within a column based on another column.

I have a dataframe with ‘zipcode’ data and ‘price’ data. I want to find the median of the ‘price’ based on the ‘zipcode’, and report it in a new column. When I run the program as is, I get a column that reports the median of the whole dataset, but I want to add the column such that we would get the median of each zip code reported. What is the piece I am missing?

”’

JavaScript

”’

Advertisement

Answer

You should groupby with zip code only

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement