I'm trying to compare two dataframes (df and df2) using .eq(), but it gives me false. I'm sure about the values:
print(df['ano'])
0 2021
Name: ano, dtype: int64
print(df2['ano'])
0 2020
1 2019
2 2019
3 2018
4 2017
...
89 2020
90 2017
91 2018
92 2021
93 2021
Name: ano, Length: 94, dtype: int64
print(df['ano'].eq(df2['ano']))
0 False
1 False
2 False
3 False
4 False
...
89 False
90 False
91 False
92 False
93 False
Name: ano, Length: 94, dtype: bool
CodePudding user response:
Series.eq(other)
compares two Series element wise, if you want to compare df2['ano']
with the first element in df1['ano']
, you can use Series.item()
or Series.iloc[0]
print(df2['ano'].eq(df['ano'].item()))
# or
print(df2['ano'].eq(df['ano'].iloc[0]))
If you want to check if element in df['ano']
is in df2['ano']
, you can use Series.isin
print(df['ano'].isin(df2['ano']))
CodePudding user response:
Solution:
df = df.drop_duplicates()
x = 0
y = 0
df = df.reset_index()
df2 = df2.reset_index()
while(x < len(df)):
while(y < len(df2)):
if((df.at[x, 'a'] == df2.at[y, 'a']) & (df.at[x, 'b'] == df2.at[y, 'b']) & (df.at[x, 'c'] == df2.at[y, 'c'])):
print('found') y = 1 x = 1 y = 0