我有一个名为"tips"的数据帧,我试图在其中删除两列,tip
和higher_than_15pct_true
,如下所示:
X = tips.drop('tip','higher_than_15pct_True', axis = 1)
这会导致以下错误:
TypeError: drop() got multiple values for argument 'axis'
我该如何解决这个问题?
根据DataFrame.drop
的 pandas 文档,您需要传递单个标签,如果您有多列,则需要传递列表:
X = tips.drop(['tip','higher_than_15pct_True'], axis = 1)
不幸的是,TypeError
最终变得非常神秘,与手头的真正问题无关。
你忘了括号。 或者使用这个
remove = ['tip','higher_than_15pct_True']
tips= df[df.columns.difference(remove)]
谢谢