python - Compare columns pandas -


i have 4 columns in 2 dataframes , want check if id1 = id2 , count1 = count2 in columns same , result 1 if match or 0 if don't. code returns 0. think doesn't iterate 1 one , in distinct row numbers. tried zip columns want, don't see difference. have ideas? thank you!

import pandas pd file1 = 'file1.csv' file2 = 'file2.csv'  df1 = read_csv(file1) df1 = read_csv(file2)  id1 = df1['id1'] count1 = df1['count1'] id2 = df2['id2'] count2 = df2['count2']  newresult = pd.concat([id1, count1, id2, count2], axis = 1) id1 = zip(df1['id1']) count1 = zip(df1['count1'])  newresult['compare'] = newresult.apply(lambda x: 1 if x['id1'] == x['id2'] , x['count1'] == x['count2'] else 0, axis = 1) 

import pandas pd import numpy np  df = pd.dataframe(np.random.randint(0, 2, (50, 4)), columns=["id1", "id2", "count1", "count2"]) df["compare"] = ((df.id1==df.id2) & (df.count1==df.count2)).astype(int) 

enter image description here


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -