Delete column from pandas DataFrame

后端 未结 17 1583
一生所求
一生所求 2020-11-22 02:44

When deleting a column in a DataFrame I use:

del df[\'column_name\']

And this works great. Why can\'t I use the following?

         


        
17条回答
  •  一个人的身影
    2020-11-22 03:21

    If your original dataframe df is not too big, you have no memory constraints, and you only need to keep a few columns, or, if you don't know beforehand the names of all the extra columns that you do not need, then you might as well create a new dataframe with only the columns you need:

    new_df = df[['spam', 'sausage']]
    

提交回复
热议问题