Columns are the different fields that contain their particular values when we create a DataFrame. We can perform certain operations on both rows & column values. Suppose we want to display all the columns except some specified columns, DataFrame.loc() helps us to achieve this task.
Syntax:
DataFrame.loc[:, df.columns!= 'column_name']
Here, the DataFrame.loc() property will read the sliced index, colon (:) means starting from the first column, DataFrame.columns will return all the columns of a DataFrame and define a specified column name after the conditional operator (!=) will return all the column names except the one which is specified inside the method.
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example:
Output:
Now, we will print the DataFrame by excluding some columns
Output 1:
Output 2:
Output 3:

need an explanation for this answer? contact us directly to get an explanation for this answer