Using describe() method to exclude a column

Question:

I am new to using python with data sets and am trying to exclude a column ("id") from being shown in the output. Wondering how to go about this using the describe() and exclude functions.

Asked By: cam.mc

||

Answers:

Use output.describe(exclude=['id'])

Answered By: robdev91

describe works on the datatypes. You can include or exclude based on the datatype & not based on columns. If your column id is of unique data type, then

df.describe(exclude=[datatype])

or if you just want to remove the column(s) in describe, then try this

cols = set(df.columns) - {'id'}
df1 = df[list(cols)]
df1.describe()

TaDa its done. For more info on describe click here

Answered By: Ajay A

You can do that by slicing your original DF and remove the ‘id’ column. One way is through .iloc . Let’s suppose the column ‘id’ is the first column from you DF, then, you could do this:

df.iloc[:,1:].describe()

The first colon represents the rows, the second the columns.

Answered By: Joao Gabriel Fekete
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.