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'))
0

1 Answer 1

2

You can use drop from pandas

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.