Reputation: 1
I have a group of keywords in two different columns in a Google Sheets. How do I compare and print the matches:
Example:
Column A
Row 1 Hi
Row 2 Hallo
Row 3 Bye
Column B
Row 1 Hi
Row 2 No
Row 3 Hallo
Print:
Hi
Hallo
Or is it possible directly in sheets? Thanks! :)
Upvotes: 0
Views: 3790
Reputation: 711
You can do it all in Google Sheets. Suppose that the first set of values is in column A and the second set of values is in column B. Then:
In a new column, paste and drag this formula: =IF(ISERROR(MATCH(B1,A:A,0)),"Not found","Found")
.
Sort the new column, and manually copy the range of values in column B that are adjacent to "Found" in the new column.
There are also other ways to do it in Google Sheets, this is just one of them.
Upvotes: 0
Reputation: 534
If you can save your file in .csv format, you can use pandas
library.
import pandas as pd
df = pd.read_csv('filename.csv')
column_1_values = set(df['A'].unique())
column_2_values = set(df['B'].unique())
matches = column_1_values.intersection(column_2_values)
print('\n'.join(map(str, matches)))
Upvotes: 1
Reputation: 46
# read column1 to list_1. there are some libs could help you.
list_1 = []
# read column2 to list_2
list_2 = []
# calc the result from list_1 and list_2
res = [x for x in list_1 for y in list_2 if x == y]
print(res)
Upvotes: 1