Extracting specific selected columns to new DataFrame as a copy

前端 未结 7 1932
忘了有多久
忘了有多久 2020-12-04 04:59

I have a pandas DataFrame with 4 columns and I want to create a new DataFrame that only has three of the columns. This question is similar

7条回答
  •  伪装坚强ぢ
    2020-12-04 05:15

    As far as I can tell, you don't necessarily need to specify the axis when using the filter function.

    new = old.filter(['A','B','D'])
    

    returns the same dataframe as

    new = old.filter(['A','B','D'], axis=1)
    

提交回复
热议问题