I have the following dataframe with two columns containing tuples, Col1 and Col3.
Check Col1 Col2 Col3
0 NaN (F123, 1) R (F123, 2)
0 NaN (F123, 1) R (F123, 6)
0 NaN (F123, 1) R (F123, 7)
Using the dictionary below how can I iterate through the columns and compare the tuples to see which have the same dictionary value and then if they do output some text to the Check col? For instance, (F123, 1) and (F123, 6) have the same dictionary value, 'R'.
The Dictionary:
df1d = {('F123', 1): 'R', ('F123', 2): 'O', ('F123', 6): 'R',
The Code I was trying:
def check_color(dictionary, value, adj_values, df):# for x in adj_values:
if tuple(x) in [k for k, v in dictionary.items() if v == dictionary[value]]:
df.set_value('Check', 'Bad')
return
for index, row in df.iterrows():
check_color(df1d, row['Col1'], row['Col3'], df)
The Desired outcome would be:
Check Col1 Col2 Col3
0 NaN (F123, 1) R (F123, 2)
0 Bad (F123, 1) R (F123, 6)
0 NaN (F123, 1) R (F123, 7)
Also, what is the correct approach to filtering out all of the rows in the dataframe that dont have a match between Col1 and Col3?
What I tried:
df[(df['ConnectorAndPin'] == df['Adj.'])]