lhux
lhux

Reputation: 33

How to remove a column in group_by statement?

I have this code:

ucla_all = ucla_all.rename(columns={'OUTSTANDING':'% Reimbursed'})
ucla_group = ucla_all.groupby(['CDS Code'])
data = pd.DataFrame(ucla_group.apply(lambda x: ((x['% Reimbursed'] != 0).value_counts(normalize=True) * 100)))
data = data.unstack().reset_index
data

and this table:

<bound method DataFrame.reset_index of          % Reimbursed            
                False       True 
CDS Code                         
2110        20.312500   79.687500
2111        13.492063   86.507937
2220        12.861953   87.138047
2221        24.734982   75.265018
2231        18.965517   81.034483

What would be the best way to remove the False column?

Upvotes: 0

Views: 83

Answers (1)

jezrael
jezrael

Reputation: 863226

Add () because DataFrame.reset_index method:

data = data.unstack().reset_index()

And then remove boolean column False without '' by DataFrame.drop:

data = data.drop(False, axis=1)

Upvotes: 1

Related Questions