擅长:python、mysql、java
<p>您的<code>feature_arr</code>有27列,但<code>feature_labels</code>只有4列,因此创建<code>pandas.DataFrame</code>失败</p>
<p>您可以使用<code>.get_feature_names()</code></p>
<pre><code>categoryVariableList = ["weekday","Month","season","weather"]
ohe = OneHotEncoder(categories='auto')
feature_arr = ohe.fit_transform(df[categoryVariableList]).toarray()
feature_labels = ohe.get_feature_names(categoryVariableList)
# feature_labels = np.array(feature_labels).ravel()
features = pd.DataFrame(feature_arr, columns=feature_labels)
features
</code></pre>