2024-03-29 00:11:59 发布
网友
以下for循环在两个数据帧上迭代不起作用:
for frame in [df_train, df_test]: frame = frame.drop('Embarked', axis=1)
我没有收到错误消息,但两个数据帧中没有删除“已装载”列。为什么?你知道吗
从help(frame.drop):
help(frame.drop)
def drop(self, labels, axis=0, level=None, inplace=False, **kwargs): """ Return new object with labels in requested axis removed ... inplace : bool, default False If True, do operation inplace and return None.
现在,您只需创建新对象并将它们命名为frame,这不会影响列表中的任何内容。您可以使用inplace=True来影响原始对象:
frame
inplace=True
for frame in [df_train, df_test]: frame.drop('Embarked', axis=1, inplace=True)
从
help(frame.drop)
:现在,您只需创建新对象并将它们命名为
frame
,这不会影响列表中的任何内容。您可以使用inplace=True
来影响原始对象:相关问题 更多 >
编程相关推荐