0

Suppose we have a Dataframe with many columns Name,Sex, Age, Education, Race. I want to create a DF only with the following columns Age,Sex,Educaion.
I know that I can do it with the following method.

df2 = pd.DataFrame(df[['Age','Sex','Education']]

Is there a way to do something like this. i.e Select all columns excepth x, y, z.

df2 = pd.DataFrame(df(select all columns except the following columns = 'Race', 'Name'))
Rustem Sadykov
  • 113
  • 1
  • 8

1 Answers1

2

You can use drop from pandas

Example: df.drop(columns=[list_of_columns_to_drop])

Maku
  • 1,476
  • 10
  • 21