我在Google表格的两个不同列中有一组关键字。如何比较和打印匹配项:
例:
Column A
Row 1 Hi
Row 2 Hallo
Row 3 Bye
Column B
Row 1 Hi
Row 2 No
Row 3 Hallo
打印:
Hi
Hallo
或者可以直接在床单上?谢谢! :)
# 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)
如果您可以以.csv格式保存文件,则可以使用pandas
库。
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)))
您可以在Google表格中完成所有操作。假设第一组值在A列中,第二组值在B列中。然后:
=IF(ISERROR(MATCH(B1,A:A,0)),"Not found","Found")
。在Google表格中还有其他方法可以做到这一点,这只是其中之一。