Returning a dataframe with all columns except for 'name'

rastawolf

Is there a more conventional or readable way of achieving the same result?

The below code works, but it feels clunky.

df[df.columns[~df.columns.isin(['name'])]]
jezrael

Use DataFrame.loc, here : means select all rows:

df.loc[:, ~df.columns.isin(['name'])]

Another idea is use DataFrame.drop with errors='ignore' for avoid errors if not exist name column (same working like solution above):

df.drop('name', axis=1, errors='ignore')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to show all of columns name on pandas dataframe?

From Java

all dataframe rows to new columns

From Dev

Calculate correlation between all columns of a DataFrame and all columns of another DataFrame?

From Dev

Sort dataframe by ALL columns in R

From Dev

RegEx pattern returning all words except those in parenthesis

From Dev

Pandas 'describe' is not returning summary of all columns

From Dev

Selecting All the columns except IDENTITY Column

From Dev

return all columns except one matrix

From Dev

Get all columns of matrix except some indices

From Dev

Piping variable name into dataframe columns

From Dev

QTreeView with QFileSystemModel: How can I remove all columns except "Name"?

From Dev

mean of all the columns of a panda dataframe?

From Dev

Groupby and lag all columns of a dataframe?

From Dev

Select All Columns Except Some in Google BigQuery?

From Dev

Adding up all columns in a dataframe

From Dev

How to show all of columns name on pandas dataframe?

From Dev

Concatenate all columns in a pandas dataframe

From Dev

Pyspark: Select all columns except particular columns

From Dev

How to plot all columns of a dataframe?

From Dev

Replace all the text in all columns except the last

From Dev

Sort dataframe by ALL columns in R

From Dev

QTreeView with QFileSystemModel: How can I remove all columns except "Name"?

From Dev

Select all row except 2 columns

From Dev

Replace pattern in all columns except in specific column

From Dev

Select all columns except one column in CakePHP?

From Dev

How to Select all columns of a table except one

From Dev

Applying to_datetime to all columns except index

From Dev

Sqlalchemy Core, insert statement returning * (all columns)

From Dev

Flatten Spark Dataframe and Name Columns

Related Related

  1. 1

    How to show all of columns name on pandas dataframe?

  2. 2

    all dataframe rows to new columns

  3. 3

    Calculate correlation between all columns of a DataFrame and all columns of another DataFrame?

  4. 4

    Sort dataframe by ALL columns in R

  5. 5

    RegEx pattern returning all words except those in parenthesis

  6. 6

    Pandas 'describe' is not returning summary of all columns

  7. 7

    Selecting All the columns except IDENTITY Column

  8. 8

    return all columns except one matrix

  9. 9

    Get all columns of matrix except some indices

  10. 10

    Piping variable name into dataframe columns

  11. 11

    QTreeView with QFileSystemModel: How can I remove all columns except "Name"?

  12. 12

    mean of all the columns of a panda dataframe?

  13. 13

    Groupby and lag all columns of a dataframe?

  14. 14

    Select All Columns Except Some in Google BigQuery?

  15. 15

    Adding up all columns in a dataframe

  16. 16

    How to show all of columns name on pandas dataframe?

  17. 17

    Concatenate all columns in a pandas dataframe

  18. 18

    Pyspark: Select all columns except particular columns

  19. 19

    How to plot all columns of a dataframe?

  20. 20

    Replace all the text in all columns except the last

  21. 21

    Sort dataframe by ALL columns in R

  22. 22

    QTreeView with QFileSystemModel: How can I remove all columns except "Name"?

  23. 23

    Select all row except 2 columns

  24. 24

    Replace pattern in all columns except in specific column

  25. 25

    Select all columns except one column in CakePHP?

  26. 26

    How to Select all columns of a table except one

  27. 27

    Applying to_datetime to all columns except index

  28. 28

    Sqlalchemy Core, insert statement returning * (all columns)

  29. 29

    Flatten Spark Dataframe and Name Columns

HotTag

Archive