比较两个熊猫数据框

时间:2019-08-17 18:15:06

标签: python pandas

例如,我在数据框中每天有“ 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)

1 个答案:

答案 0 :(得分:0)

如果您只想比较两个行情清单,可以尝试执行以下操作:

daily =  set("AAPL,MSFT,TSLA,AMZN".split(","))
weekly = set("OAG,EXCA,AAPL,HRT,TSLA".split(","))
common = daily.intersection(weekly)

在这里,common将是:{'TSLA', 'AAPL'}