How to iterate over rows in pandas data frame, with reference to two column at the same time

Question:

I have a df as seen below, I want to calculate average from speed_InMeterS column, with respect to time, and lane. In other word, at time 1 I need average speed for lane x.

enter image description here

I tried, but I can only make reference to one column (time). I’m expecting to computer the average speed for each lane at time T.

Asked By: Mustybichi

||

Answers:

You didn’t add the df,
If I understand correctly, you want to have the average speed_InMeterS for each time and lane. for that you don’t need to iterate. you should use groupby:

time_lane_mean_speed = df.groupby(["time", "lane"]).agg({"speed_InMeterS": "mean"})

Please elaborate any more details for a better answer

Answered By: Matan Bendak