我是Python的初学者,我学习一本教科书来学习Pandas模块。 我有一个名为Berri_bike的数据帧,它来自以下代码:
bike_df=pd.read_csv(os.path.join(path,'comptagevelo2012.csv'),parse_dates=['Date'],\
encoding='latin1',dayfirst=True,index_col='Date')
Berri_bike=bike_df['Berri1'].copy() # get only the column='Berri1'
Berri_bike['Weekday']=Berri_bike.index.weekday
weekday_counts = Berri_bike.groupby('Weekday').aggregate(sum)
weekday_counts
我的Berri_bilk中有3列,一个数据索引-从2012年1月1日到2012年12月31日,value列中有每个数据的数字,还有一个我分配给它的工作日列。但是当我想按值分组时,我得到了一个错误:ValueError:Grouper和axis的长度必须相同,我不确定这意味着什么,我想做的很简单,就像在SQL中,sum(value)grouped weekday。。。有谁能告诉我这里发生了什么事吗?在
将列复制到pandas系列而不是新的数据帧中,因此执行以下操作behave differently。如果您打印出
Berri_bike
,您可以看到这一点,因为它不显示列名。相反,您应该copy the column into a new dataframe:
相关问题 更多 >
编程相关推荐