為什么以下代碼引發(fā)異常:# creates empty data frame with two columnsmy_df = pd.DataFrame([], columns=["a", "b"])# groups by the values in column "a" and transforms the values in "b" to be the summy_df.groupby("a")["b"].transform(lambda x: x.sum())但是,這導致此錯誤:ValueError: No objects to concatenate如果my_df不為空,它將起作用:list_of_numbers = [[0, 1], [0, 2], [1, 10]]my_df = pd.DataFrame(list_of_numbers, columns=["a", "b"])my_df.groupby("a")["b"].transform(lambda x: x.sum())0 31 32 10Name: b, dtype: int64但my_df來自應(yīng)用程序的其他部分,因此可以為空。我正在使用Pandas 0.20.3。
添加回答
舉報
0/150
提交
取消