Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Pandas segmenting groupby average brocq_18 Programmer named Tim Posts: 16 Threads: 5 Joined: Mar 2017 Reputation: 0 Likes received: 0 #1 Jul-11-2018, 10:54 AM (This post was last modified: Jul-11-2018, 10:55 AM by brocq_18. Edited 1 time in total.) I have 3 columns in a pandas dataframe, cars bikes and price. I want to find the average price per cars and bikes. The data seems to have decimal values for bikes. 3, 1, 221.90 3, 2.5, 538.00 2, 1.25, 180.00 4, 3.5, 604.00 3, 0.75, 510.00 4, 4.5, 123.06 3, 2.5, 257.50 3, 1.5, 291.85 I use `vehicle.groupby(['cars', 'bikes'])['price'].mean()` to get the mean. This gives me the below columns of cars, bikes and average price. 0, 0.00, 545.20 0, 0.75, 234.06 0, 1.00, 256.26 1, 0.00, 285.76 1, 0.50, 237.54 1, 0.75, 234.52 1, 1.00, 374.11 2, 0.50, 123.97 2, 0.75, 343.24 How can I segment this so all values for bikes <1 is considered 1, all values for bikes <2 is considered 2 etc and then work out the average? « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post How to use bfill und groupby under conditions karlito 1 315 Dec-13-2019, 07:03 PM Last Post: ibreeden Code improvement: groupby and operation on conditionals pythonidae 6 327 Dec-12-2019, 05:58 AM Last Post: pythonidae itertuples, datetime, pandas, groupby, in range karlito 0 411 Nov-29-2019, 11:35 AM Last Post: karlito Groupby([]).sum() Miscalculation mini_geek 1 278 Sep-16-2019, 12:43 AM Last Post: Larz60+ Groupby in pandas with conditional - add and subtract rregorr 2 1,442 Jul-12-2019, 05:17 PM Last Post: rregorr groupby question smw10c 2 1,374 Mar-29-2017, 11:17 PM Last Post: smw10c

Forum Jump:

Users browsing this thread: 1 Guest(s)