I have two dataframes:
df1
Index | geoid10 | precinct_2020 |
---|---|---|
1 | 360050020002003 | 43 |
2 | 360610005001008 | 1 |
3 | 360610008006013 | 5 |
4 | 360610151003000 | 20 |
5 | 360610241002002 | 33 |
6 | 360050255001000 | 52 |
7 | 360470002001014 | 72 |
df2
Index | geoid10 | precinct_2020 | population |
---|---|---|---|
0 | 360610005001008 | 750 | 0 |
1 | 360610008006013 | 750 | 0 |
2 | 360610241002002 | 750 | 0 |
3 | 360050255001000 | 750 | 1990 |
4 | 360470002001014 | 750 | 333 |
As you can see, the 'geoid10' columns in df1 and df2 have matching values. However, when I try to search for each value of df1's geoid10 column inside df2's geoid10 column, my code returns "false". I have made sure that both 'geoid10' columns are ints. Why is this happening?
Here is the sample for loop:
for gid in df1['geoid10']:
if gid in df2['geoid10']:
print("true")
else:
print("false")
Output:
false
false
false
false
false
false
false
false