我收到一个熊猫数据帧。 它充满了不必要的功能,我想删除。 现在我在做下面的事情,这是肮脏的 我怎么能用一种更像Python的方式
features_to_include= mydf.columns.tolist()
features_to_include=[f for f in features_to_include if 'stopword1' not in f]
features_to_include=[f for f in features_to_include if 'stopwordN' not in f]
[。。。其他90个]
features_to_include=[f for f in features_to_include if 'password1' in f]
features_to_include=[f for f in features_to_include if 'passwordN' in f]
[。。。其他90个]
编辑:'stopword1'和'password1'在X.columns
中不是
X.columns
的示例名称可以是:feature99_stopword1
您可以尝试使用^{} :
或者如果我们有一份清单:
我认为需要^{} :
样本:
相关问题 更多 >
编程相关推荐