pandas到numpy矩阵的转换会删除列



我有以下数据帧,但需要将其作为numpy数组传递到Keras中。我需要保留month、year、shop_id和item_id列,但numpy数组会删除它们,只保留item_category_id和avg_item_price。

month year shop_id item_id item_category_id  avg_item_price
01    2013 0       32                    160      147.333328
33                    111      347.000000
35                     40      247.000000

最后它说有

[32920 rows x 2 columns]

如果这些列被用作panda中的索引,则必须重置它们:

df = df.reset_index()

最新更新