Selecting multiple columns in a pandas dataframe

后端 未结 19 1787
醉话见心
醉话见心 2020-11-22 00:08

I have data in different columns but I don\'t know how to extract it to save it in another variable.

index  a   b   c
1      2   3   4
2      3   4   5
         


        
19条回答
  •  既然无缘
    2020-11-22 00:32

    You could provide a list of columns to be dropped and return back the DataFrame with only the columns needed using the drop() function on a Pandas DataFrame.

    Just saying

    colsToDrop = ['a']
    df.drop(colsToDrop, axis=1)
    

    would return a DataFrame with just the columns b and c.

    The drop method is documented here.

提交回复
热议问题