我有一个包含38列的数据帧,其中一列是时间。我建立了一个二进制框架空间
timeframe=['4-6','7-9','10-12','13-15','16-18','19-21','22-24' ]
bins = [3,6,9,12,15,18,21,24]现在我来切开:
frameddata=pd.cut(df['time'],bins,retbins=True, labels=timeframe)并希望将df分组用于不同的存储箱:
groups=df.groupby(frameddata)在这里,我得到了以下错误:
ValueError: Grouper and axis must be same length对此有什么帮助吗?
发布于 2018-04-09 19:41:30
我认为需要创建一个新的专栏:
df['bins'] = pd.cut(df['time'],bins,retbins=True, labels=timeframe)
groups=df.groupby('bins')但是你可能会在新的列中得到一些NaN,因为值在4-24范围之外,所以groupby会默默地删除这些行。
https://stackoverflow.com/questions/49732049
复制相似问题