Я бы переписал код следующим образом (более читабельным):
# Create a sample dataframe
data = [(1 , 3, 3 , 3),
(0.5, 1, 0.25, 1),
(6 , 7, 8 , 8)]
df = pd.DataFrame(data,
columns=['x1', 'x2', 'x3', 'max'],
index =['x1', 'x2', 'x3'])
print(df)
# Your code could be rewriten like the following
col_names = df.columns.values
row_names = df.index
for row, cols in df.iterrows():
max = cols['max']
other_cols = cols.drop('max')
print("Max", end =" ")
for col in range(len(other_cols)):
if other_cols[col] == max:
print('(', row, ',', col_names[col], ')', end =" ")
print()
Надеюсь, это поможет.