Home > Net >  Compare two column value in dataframe and calculate percentage of values similar in two columns
Compare two column value in dataframe and calculate percentage of values similar in two columns

Time:08-01

I am having dataframe df.

I want to compare two columns in dataframe and want to find accuracy or percentage of rows which contain same values in both columns.

df

predicted_value     actual_value     
0                       1
1                       1
0                       0
1                       1

Output- 75% of values are matching between two columns in pandas dataframe.

CodePudding user response:

acc = (df.predicted_value==df.actual_value).mean()

if you want to format the accuracy in percentage:

print("%.2f%%"%(acc*100))
  • Related