Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
762 B
4
Indexable
Never
class_values=[]
for i, row in df.iterrows():
    m_values = [row['M1']+row['M2']+row['M3']+row['M4']+row['M5']+row['M6']+row['M7']+row['M8']+row['M9']]
    n_values = [row['N1']+row['N2']+row['N3']+row['N4']+row['N5']+row['N6']+row['N7']+row['N8']+row['N9']]
    p_values = [row['P1']+row['P2']+row['P3']+row['P4']+row['P5']+row['P6']+row['P7']+row['P8']+row['P9']]
    min_val = min(3.86-sum(m_values)/9, 3.68-sum(n_values)/9, 3.4-sum(p_values)/9)
    if min_val == 3.86-sum(m_values)/9:
        class_values.append(0)
    elif min_val == 3.68-sum(n_values)/9:
        class_values.append(1)
    else:
        class_values.append(2)

# Add the 'Class' column to the DataFrame
df['Class'] = class_values
df = df.drop(['country', 'source'], axis=1)