There is a correlation matrix. I need to get maximum ignoring certain columns. To do this, I attached another column to the matrix with labels as a filter for filtering such columns.
The task is to calculate the maximum, excluding from the calculation of the row, where in the column "CLASS" is one. Since the matrix is square, the "CLASS" column can also be used as a string.
Below is the code for my implementation. It works correctly, but very slowly on large tables! Help me find a quick way to calculate vector pandas. I do not have enough memory to work with large dataframes with this approach.
df = pd.read_csv('https://st.storeland.ru/9/2418/212/demo10.csv', sep=';', index_col=0) def noise_porog(Series_cor): noise_list = list() priznaki = list(df['CLASS']) CLASS = 1 for idx, crl in enumerate(Series_cor[:-1]): if priznaki[idx] != CLASS: noise_list.append(Series_cor[idx]) # список шумов else: pass return pd.Series(max(noise_list)) df['max_01'] = df.apply(noise_porog, axis=1) Here is a screen for clarity. I selected the first iteration, where I select the necessary columns and from them I get the maximum and write to the new column "max_01": 
Here is a larger matrix:
df = pd.read_csv('https://st.storeland.ru/6/2418/067/demo.csv', sep=',', index_col=-1) df = df.loc[:, ~df.columns.str.contains('unnamed', case=False)].T df For convenience, I made the values from "CLASS" as column names.