如何解决Lambda 函数在合并数据帧时出现问题
for column in all_data[categorical_cols]:
all_data[column].fillna(lambda x: x.fillna(x.value_counts().index[0]),inplace=True)
dummies_cols_created = pd.get_dummies(all_data[categorical_cols])
all_data = pd.merge(all_data[numeric_cols],all_data[dummies_cols_created],how='outer')
我在下面粘贴错误信息。
ValueError Traceback (most recent call last)
<ipython-input-116-6a8a533bba3e> in <module>
----> 1 all_data = pd.merge(all_data[numeric_cols],how='outer')
/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self,key)
2887 # Do we have a (boolean) DataFrame?
2888 if isinstance(key,DataFrame):
-> 2889 return self.where(key)
2890
2891 # Do we have a (boolean) 1d indexer?
/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in where(self,cond,other,inplace,axis,level,errors,try_cast)
9003 other = com.apply_if_callable(other,self)
9004 return self._where(
-> 9005 cond,errors=errors,try_cast=try_cast
9006 )
9007
/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in _where(self,try_cast)
8764 for dt in cond.dtypes:
8765 if not is_bool_dtype(dt):
-> 8766 raise ValueError(msg.format(dtype=dt))
8767 else:
8768 # GH#21947 we have an empty DataFrame/Series,could be object-dtype
ValueError: Boolean array expected for the condition,not int64
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。