擅长:python、mysql、java
<p>您需要将<code>timedelta</code>转换成一些数值,例如<code>int64</code>通过<code>values</code>转换成<code>int64</code>最准确的值,因为转换成<code>ns</code>是<code>timedelta</code>的数值表示:</p>
<pre><code>dropped['new'] = dropped['diff'].values.astype(np.int64)
means = dropped.groupby('bank').mean()
means['new'] = pd.to_timedelta(means['new'])
std = dropped.groupby('bank').std()
std['new'] = pd.to_timedelta(std['new'])
</code></pre>
<p>另一种解决方案是通过<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.total_seconds.html" rel="noreferrer">^{<cd7>}</a>将值转换为<code>seconds</code>,但这样做不太准确:</p>
<pre><code>dropped['new'] = dropped['diff'].dt.total_seconds()
means = dropped.groupby('bank').mean()
</code></pre>