python/pandas,如何填充持续时间列的缺失值?
我的数据(DF)具有一个“ duration_time”列,其值在几分钟和几秒钟内:10:43
这些值在5到15分钟之间。
此列的数据类型是“对象”。
此列中有几个缺少值。
是否有一种方法可以用本列的平均值填充这些缺失的值?
我尝试了不同的方法,但没有结果。df ['duration_time'] = df ['duration_time']。fillna(df ['duration_time']。平均值())
我收到了此消息:
只能串联str(不是“ int”)
typeError:当我尝试计算列的平均值时, :
df ['duration_time']。平均()
我收到以下消息:typeError:只能串联str(不是“ int”)
提前感谢您的帮助!
My data (df) has a column "duration_time" with values in minutes and seconds like this:10:43
These values range from 5 to 15 minutes.
The data type of this column is 'object'.
There is a couple of missing values in this column.
Is there a way to fill these missing values with the mean of this column?
I have tried different methods but no result.df['duration_time'] = df['duration_time'].fillna(df['duration_time'].mean())
I got this message:TypeError: can only concatenate str (not "int") to str
When I just try to calculate the mean of the column as this:df['duration_time'].mean()
I get the following message:TypeError: can only concatenate str (not "int") to str
Thank you in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的系列DF ['duration_time']实际上不是DateTime类型的。
如果我这样做:
那么我可以重现您的错误。
但是,如果我将该系列包装到to_dateTime()中,则您的代码有效:
I think your Series df['duration_time'] is not actually of datetime type.
If I do:
Then I can reproduce your error.
But if I wrap that series into a to_datetime(), then your code works: