本文介绍了ValueError:石斑鱼和轴的长度必须相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含38列的数据框,其中之一是时间.我建立了一个垃圾箱空间
I have a dataframe with 38 columns, one of them is Time.I established a bin frame space
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分组为不同的垃圾箱:
and want to group the df for different bins:
groups=df.groupby(frameddata)
在这里我得到以下错误:
here I get the following error:
ValueError: Grouper and axis must be same length
对此有任何帮助吗?
推荐答案
我认为需要创建新列:
df['bins'] = pd.cut(df['time'],bins,retbins=True, labels=timeframe)
groups=df.groupby('bins')
但是可能会在新列中得到一些NaN
,因为值在4-24
范围之外,所以groupby
会静默删除这些行.
But is possible you get some NaN
s in new column, because values outside of range 4-24
, so groupby
silently remove these rows.
这篇关于ValueError:石斑鱼和轴的长度必须相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!