Drop columns from pandas dataframe, regardless of whether ALL column names are present

TheChymera

I would like to use df.drop(drop_list, axis=1) to remove a number of columns from my data frame, however if an entry from drop_list is not present in df.columns.tolist(), the command fails, how can I prevent this from happening?

tanemaki
df.drop(set(drop_list) & set(df.columns), axis=1)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Drop columns from pandas dataframe, regardless of whether ALL column names are present

From Dev

what is the fast way to drop columns in pandas dataframe from a list of column names

From Dev

Remove last two characters from column names of all the columns in Dataframe - Pandas

From Dev

Remove last two characters from column names of all the columns in Dataframe - Pandas

From Dev

python pandas selecting columns from a dataframe via a list of column names

From Dev

python pandas selecting columns from a dataframe via a list of column names

From Dev

Python Pandas - Main DataFrame, want to drop all columns in smaller DataFrame

From Dev

Pandas extract columns from dataframe which are not present in another dataframe

From Dev

Pandas: How to drop leading missing values for all columns in a pandas dataframe?

From Dev

Pandas subtract each column in dataframe_a from all columns of dataframe_b and write result to third dataframe

From Dev

Build list from column names Pandas DataFrame

From Dev

How to drop a column dataframe (df) in Pandas based on condition if the column is present in df?

From Dev

Creating new dataframe columns from existing dataframe column names

From Dev

Split a text(with names and values) column into multiple columns in Pandas DataFrame

From Dev

Pandas dataframe drop columns with no header

From Java

Drop columns whose name contains a specific string from pandas DataFrame

From Java

List of Dataframes, drop Dataframe column (columns have different names) if row contains a special string

From Dev

Drop all data in a pandas dataframe

From Dev

Creating new columns from pandas df column names and values

From Dev

All possible permutations columns Pandas Dataframe within the same column

From Dev

Pandas: Force position of column in DataFrame (without knowing all columns)

From Dev

pandas automatically create dataframe from list of series with column names

From Dev

Pandas copy column names from one dataframe to another

From Dev

Python Pandas Setting Dataframe index and Column names from an array

From Dev

Extracting 4 digit column names from pandas dataframe

From Dev

How to prevent Pandas Dataframe from repeating column names at every row?

From Dev

Compare column names of Pandas Dataframe

From Dev

Pandas drop duplicates if reverse is present between two columns

From Dev

Drop columns with low standard deviation in Pandas Dataframe

Related Related

  1. 1

    Drop columns from pandas dataframe, regardless of whether ALL column names are present

  2. 2

    what is the fast way to drop columns in pandas dataframe from a list of column names

  3. 3

    Remove last two characters from column names of all the columns in Dataframe - Pandas

  4. 4

    Remove last two characters from column names of all the columns in Dataframe - Pandas

  5. 5

    python pandas selecting columns from a dataframe via a list of column names

  6. 6

    python pandas selecting columns from a dataframe via a list of column names

  7. 7

    Python Pandas - Main DataFrame, want to drop all columns in smaller DataFrame

  8. 8

    Pandas extract columns from dataframe which are not present in another dataframe

  9. 9

    Pandas: How to drop leading missing values for all columns in a pandas dataframe?

  10. 10

    Pandas subtract each column in dataframe_a from all columns of dataframe_b and write result to third dataframe

  11. 11

    Build list from column names Pandas DataFrame

  12. 12

    How to drop a column dataframe (df) in Pandas based on condition if the column is present in df?

  13. 13

    Creating new dataframe columns from existing dataframe column names

  14. 14

    Split a text(with names and values) column into multiple columns in Pandas DataFrame

  15. 15

    Pandas dataframe drop columns with no header

  16. 16

    Drop columns whose name contains a specific string from pandas DataFrame

  17. 17

    List of Dataframes, drop Dataframe column (columns have different names) if row contains a special string

  18. 18

    Drop all data in a pandas dataframe

  19. 19

    Creating new columns from pandas df column names and values

  20. 20

    All possible permutations columns Pandas Dataframe within the same column

  21. 21

    Pandas: Force position of column in DataFrame (without knowing all columns)

  22. 22

    pandas automatically create dataframe from list of series with column names

  23. 23

    Pandas copy column names from one dataframe to another

  24. 24

    Python Pandas Setting Dataframe index and Column names from an array

  25. 25

    Extracting 4 digit column names from pandas dataframe

  26. 26

    How to prevent Pandas Dataframe from repeating column names at every row?

  27. 27

    Compare column names of Pandas Dataframe

  28. 28

    Pandas drop duplicates if reverse is present between two columns

  29. 29

    Drop columns with low standard deviation in Pandas Dataframe

HotTag

Archive