0

I try to compare two excel files with one table in each other. I've succeeded to create a merged table and defined the third column. When the value of first column equal to value of the second column I succeeded to write match in the third column. But when the values are not equal - I want to write 'not matched' but don't know how...

I think i write np.where function wrong, so please help me with it. I don't want use select/condition python functions

import pandas as pd
import numpy as np

ff1 = pd.read_csv(r'C:\Users\dbokov\Desktop\ff1.csv', index_col=0)

ff0 = pd.read_csv(r'C:\Users\dbokov\Desktop\ff0.csv', index_col=0)

#print(A)
#print(B)

C = pd.merge(left=ff1, right=ff0, how='outer', left_index=True, right_index=True, suffixes=['_ff1', '_ff0'])
df = pd.DataFrame(data=C, columns= ['COUNT_ff1', 'COUNT_ff0'])
#print(C)
#print(df)

df['que'] = np.where('COUNT_ff1' == 'COUNT_ff0'), 'match'

print (df)

 my result:

                     COUNT_ff1  COUNT_ff0    que
    hina_marketer_id                             
    145130                    3          2  ([],)
    1                         4          4  match
Dima Bokov
  • 91
  • 1
  • 14

1 Answers1

1

IICU, You just have to complete your np.where accoring to format. Try this.

df['que'] = np.where(df['COUNT_ff1'] == df['COUNT_ff0'], 'match','not matched')
moys
  • 7,747
  • 2
  • 11
  • 42