[英]Group by column and get mean of the the group pandas
I have a dataframe like below 我有一个如下数据框
Mode Time
Air 2
Sea 4
Air 5
Sea 6
So I want to have the output as 所以我想输出为
Mode Time
Air 3.5
Sea 5
The output should contain two columns Mode and the Time. 输出应包含两列“模式”和“时间”。
With my Code I dont see the columns coming. 与我的代码,我看不到列。 Below is my code: 下面是我的代码:
mean_remaining_shipment_time_mode=training_data.groupby('mode')['Time'].mean()
The output of this is: 输出为:
Series: mode
Air 3.813711
Ocean 14.670060
Parcel 3.036790
Truck 3.097268
Name: remainingShiptime, dtype: float64
Don't select the column: 不要选择该列:
>>> df1.groupby('Mode').mean()
Time
Mode
Air 3.5
Sea 5.0
>>>
>>> df1.groupby('Mode').mean().reset_index()
Mode Time
0 Air 3.5
1 Sea 5.0
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.