Pandas Python分组数据盒p

2024-03-29 12:55:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着按小时分组时间戳数据,然后用0填充nan,然后为每小时创建一个盒线图。我尝试了以下代码:

df.groupby(df.index.hour).fillna(0).boxplot()

并得到以下错误:索引器错误:列表索引超出范围

有什么关于如何用0代替nan来创建箱线图的帮助吗?在

样品df如下。endDate是索引:

endDate sourceName  sourceVersion   device  type    unit    creationDate    startDate   value
9/24/2014 15:07 iPhone          StepCount   count   10/2/2014 8:30  9/24/2014 15:07 47
9/24/2014 15:12 iPhone          StepCount   count   10/2/2014 8:30  9/24/2014 15:12 518
9/24/2014 15:17 iPhone          StepCount   count   10/2/2014 8:30  9/24/2014 15:17 608
9/24/2014 15:22 iPhone          StepCount   count   10/2/2014 8:30  9/24/2014 15:22 541
9/24/2014 15:27 iPhone          StepCount   count   10/2/2014 8:30  9/24/2014 15:27 823

Tags: 数据代码dfindexcount错误时间nan