How to add mean,minimum,max column for this given dataframe?

Viewed 15

I was trying to add a new column mean_dist which is based on sim_distance and Distance

for example:for the first four rows in sim_distance,the Distance are different and want to get mean of those values in column(mean_distance)

Similarly i want to add new column like min_dist,max_dist,min_azi,max azi and standard deviation.

I tried to add mean as follows and it didn't worked:

df2['Mean_dist'] = df2.groupby('Current_Sim_distance_r_obj1')['Distance'].mean()

The sample data is as below:

Cycle_Count Sim_Azi Sim_distance Azimuth Distance
87417 -55 3.38 -55.85 4.38
87419 -55 3.38 -55.86 4.37
87419 -55 3.38 -55.86 4.37
87435 -55 3.38 -55.84 4.37
87441 -55 7.92 -55.84 7.47
87447 -55 7.92 -55.95 7.45
87459 -55 7.92 -55.86 7.78
87465 -55 7.92 -55.98 7.35
87471 -45 7.38 -45.84 7.37
87474 -45 7.38 -45.96 7.35
87984 -45 7.38 -40.86 7.95
87984 -45 7.38 -40.86 7.85
88026 -45 8.58 -40.87 8.86

Expected output:

Cycle_Count Sim_Azi Sim_distance Azimuth Dist Mean_dist
87417 -55 3.38 -55.85 4.38 4.37
87419 -55 3.38 -55.86 4.37
87419 -55 3.38 -55.86 4.37
87435 -55 3.38 -55.84 4.37
87441 -55 7.92 -55.84 7.47 7.51
87447 -55 7.92 -55.95 7.45
87459 -55 7.92 -55.86 7.78
87465 -55 7.92 -55.98 7.35
87471 -45 7.38 -45.84 7.37 7.63
87474 -45 7.38 -45.96 7.35
87984 -45 7.38 -40.86 7.95
87984 -45 7.38 -40.86 7.85
88026 -45 8.58 -40.87 8.86

I am not good at pandas.Could someone can help me?

0 Answers
Related