从列名列表中删除pandas数据帧中列的快速方法是什么?

时间:2016-11-15 02:24:19

标签: python pandas dataframe

我正在尝试找出使用列名列表在df中删除列的最快方法。这是一种奇特的功能减少技术。 这就是我现在正在使用的东西,它将永远消失。任何建议都非常感谢。

    important2=(important[:-(len(important)-500)]) 
    for i in important:
        if i in important2:
            pass
        else:
            df_reduced.drop(i, axis=1, inplace=True)
    df_reduced.head()

1 个答案:

答案 0 :(得分:13)

使用包含要删除的列的list

good_bye_list = ['column_1', 'column_2', 'column_3']
df_reduced.drop(good_bye_list, axis=1, inplace=True)
相关问题