例如,我在数据框中每天有“ AAPL,MSFT,TSLA,AMZN”,在每周列表中有“ OAG,EXCA,AAPL,HRT,TSLA”
当在两个列表中都找到一个报价器时,如何比较两个数据框并打印出来?
dailyList = []
weeklyList = []
for ticker in tickers:
dailyList.append(ticker)
weeklyList.append(ticker) # append with some data like "AAPL"
compare(dailyList,weeklyList)
print(matchingTickers)
答案 0 :(得分:0)
如果您只想比较两个行情清单,可以尝试执行以下操作:
daily = set("AAPL,MSFT,TSLA,AMZN".split(","))
weekly = set("OAG,EXCA,AAPL,HRT,TSLA".split(","))
common = daily.intersection(weekly)
在这里,common
将是:{'TSLA', 'AAPL'}
。