如何使用 Keras.to_Categorical 在 dataFrame 中一次对多列进行 One-Hot 编码?

How to One-Hot encode multiple columns at once in dataFrame using Keras.to_Categorical?

我想使用 Keras to_categorical 一次对数据框中的多个列进行一次性编码。怎么做?

need_to_encode = ['Item_Fat_Content', 'Outlet_Location_Type', 'Outlet_Type', 'Outlet_Size', 'Item_Type_Combined', 'Outlet']

这些是我需要进行单热编码的列。

好吧,您可以在需要对数据进行编码的每一列上使用此 util 函数。

或者您在需要编码的数据帧部分使用 scikit-learn's categorical encoder

下次别忘了附上一个minimal working example,这样我们可以提供进一步的帮助。