我想在我創(chuàng)建的pandas.DataFrame上使用apply,并為每一行返回一個值列表,其中每個值本身就是一列。我寫了以下代碼:import pandas as pddef get_list(row): return [i for i in range(5)]df = pd.DataFrame(0, index=np.arange(100), columns=['col'])df.apply(lambda row: get_list(row), axis=1, result_type='expand')當(dāng)我添加result_type='expand'以將返回的數(shù)組更改為單獨(dú)的列時,出現(xiàn)以下錯誤:TypeError: ("<lambda>() got an unexpected keyword argument 'result_type'", 'occurred at index 0')但是,如果我刪除result_type它運(yùn)行良好的字段(返回一列數(shù)組),可能是什么問題?我正在使用colab來運(yùn)行我的代碼
添加回答
舉報(bào)
0/150
提交
取消