Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve DataFrame of all but one specified column [duplicate]

Is there a way to select all but one column in a pandas DataFrame object? I've seen ways to delete a column, but I don't want to do that.

like image 630
user1802143 Avatar asked Nov 26 '13 23:11

user1802143


People also ask

How do you subset all but one column in pandas?

To select all columns except one column in Pandas DataFrame, we can use df. loc[:, df. columns != <column name>].

How do I exclude one column from a DataFrame?

We can exclude one column from the pandas dataframe by using the loc function. This function removes the column based on the location. Parameters: dataframe: is the input dataframe.

How do you find duplicate rows in a DataFrame based on all or a list of columns?

Find Duplicate Rows based on all columns To find & select the duplicate all rows based on all columns call the Daraframe. duplicate() without any subset argument. It will return a Boolean series with True at the place of each duplicated rows except their first occurrence (default value of keep argument is 'first').


2 Answers

use drop method:

df.drop(column_name, axis=1) 
like image 119
HYRY Avatar answered Sep 28 '22 18:09

HYRY


df.loc[:, df.columns != col] 

where col is the name of the column to leave out.

like image 33
lev Avatar answered Sep 28 '22 20:09

lev