Group by column and get mean of the the group pandas
<p>I have a dataframe like below </p>

<pre><code>Mode   Time
Air    2
Sea    4
Air    5
Sea    6
</code></pre>

<p>So I want to have the output as </p>

<pre><code>Mode   Time 
Air    3.5
Sea    5
</code></pre>

<p>The output should contain two columns Mode and the Time.</p>

<p>With my Code I dont see the columns coming. Below is my code:</p>

<pre><code>mean_remaining_shipment_time_mode=training_data.groupby('mode')['Time'].mean()
</code></pre>

<p>The output of this is:</p>

<pre><code>Series: mode
Air        3.813711
Ocean     14.670060
Parcel     3.036790
Truck      3.097268
Name: remainingShiptime, dtype: float64
</code></pre>

<p>Don't select the column:</p>

<pre><code>&gt;&gt;&gt; df1.groupby('Mode').mean()
      Time
Mode      
Air    3.5
Sea    5.0
&gt;&gt;&gt; 
</code></pre>

<h2>Edit in response to comment</h2>

<pre><code>&gt;&gt;&gt; df1.groupby('Mode').mean().reset_index()
  Mode  Time
0  Air   3.5
1  Sea   5.0
&gt;&gt;&gt;
</code></pre>

python pandas dataframe