Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I have a data frame that I want to separate into bins and assign each bin the median value of the values in that bin.

   POA   Egrid           

   200   1.17

   205   0.63

   275   1.08

   325   1.22

   350   0.57

The result should look like

   POA       Egrid           

 (200,300)   Median of (1.17,0.63,1.08)

 (300,400)   Median of (1.22,0.57)

I tried to write 2 loops, but could not figure out the median part. 

1 Answer

0 votes
by (36.8k points)

Do with

s=df.groupby(pd.cut(df.POA,[100,200,300])).Egrid.median().reset_index()

          POA  Egrid

0  (100, 200]  1.170

1  (200, 300]  0.855

 Do check out Data Science with Python course which helps you understand from scratch 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...