Using Series.difference() to select all columns, except one given column
Using Series.difference() method and [ ] operator together. Series.difference() Method returns a new Index with elements from the index that are not in other.
Example: Select all columns, except one ‘student_name’ column in Pandas Dataframe.
Python3
df = data[data.columns.difference([ 'student_name' ])] # show the dataframe df |
Output:
Select all columns, except one given column in a Pandas DataFrame
DataFrame Data structure are the heart of Pandas library. DataFrames are basically two dimension Series object. They have rows and columns with rows representing the index and columns representing the content. Now, let’s see how to Select all columns, except one given column in Pandas DataFrame in Python.