Reputation: 344
I have pandas dataframe like below.
index col_A col_B col_C col_D col_E
a 12 15 28 34 23
b 23 37 46 34 92
c 34 32 24 93 12
d 12 0 1 0 0
I want output like below.
index col_B col_D col_E
a 15 34 23
b 37 34 92
c 32 93 12
d 0 0 0
The output frame condition is like if there is 0 in index d row. It should be in output dataframe.
Upvotes: 1
Views: 682
Reputation: 862611
Use DataFrame.loc
for select index d
and then filter by another DataFrame.loc
with :
for all rows and condition for filter columns:
df = df.loc[:, df.loc['d'].eq(0)]
print (df)
col_B col_D col_E
index
a 15 34 23
b 37 34 92
c 32 93 12
d 0 0 0
Upvotes: 2