python - Drop row and column of a dataframe that contains the non-zero minimum -


i have symmetric pandas dataframe. want drop column , row contains non-zero minimum of whole dataframe.

for example if consider:

       b    c    d    e   0    2    1    5    3 b   2    0    7    4    8 c   1    7    0    10   6 d   5    4    10   0    11 e   3    8    6    11   0 

i want drop [row a, col c] , therefore [row c, col a] contains 1 (minimum). expected output is:

    b    d    e b   0    4    8 d   4    0    11 e   8    11   0 

what fastest method can that?

iiuc select data dataframe without dropping loc:

mask = ~(df ==1).any() in [29]: df.loc[mask, mask] out[29]:      b   d   e b  0   4   8 d  4   0  11 e  8  11   0 

edit

to find minimum value dataframe except 0 use twice min, first find minimum value through column , second find minimum value of resulted series:

in [48]: df[df != 0].min().min() out[48]: 1.0 

then pass in above solution:

min_val = df[df != 0].min().min() mask = ~(df == min_val).any()  in [50]: df.loc[mask, mask] out[50]:     b   d   e b  0   4   8 d  4   0  11 e  8  11   0 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -