【发布时间】:2018-04-19 22:37:04
【问题描述】:
我正在使用带有pandas 和sklearn 的python,并尝试使用新的非常方便的sklearn-pandas。
我有一个大数据框,需要以类似的方式转换多个列。
我在变量other 中有多个列名
源代码文档here
明确指出有可能使用相同的转换来转换多个列,但以下代码的行为与预期不同:
from sklearn.preprocessing import MinMaxScaler, LabelEncoder
mapper = DataFrameMapper([[other[0],other[1]],LabelEncoder()])
mapper.fit_transform(df.copy())
我收到以下错误:
raise ValueError("bad input shape {0}".format(shape)) ValueError: ['EFW', 'BPD']: bad input shape (154, 2)
当我使用以下代码时,效果很好:
cols = [(other[i], LabelEncoder()) for i,col in enumerate(other)]
mapper = DataFrameMapper(cols)
mapper.fit_transform(df.copy())
据我了解,两者都应该运行良好并产生相同的结果。 我在这里做错了什么?
谢谢!
【问题讨论】:
标签: python pandas dataframe scikit-learn sklearn-pandas