有两个表,一个是商品的每日市场价格,另一个是采购报告。现在我想比较市场价格和销售价格我怎么做才能有效
市场价格
date,commodity,price
2008-12-01,akfuh3,850
2008-12-02,akfuh3,1034
2008-12-03,akfuh3,1220
2008-12-05,akfuh3,1000
purches_report
date,dealer,commodity,sale_price
2008-12-01,ABC,akfuh3,850
2008-12-01,XYZ,akfuh3,855
2008-12-02,ABC,akfuh3,900
2008-12-03,ABC,akfuh3,1300
2008-12-03,XYZ,akfuh3,1300
2008-12-05,PQR,akfuh3,1050
我将两者合并,然后比较两列,但会占用更多内存,因为每个日期可能有多次购买,并且会为每个日期制作多个 sale_price 副本。
full_report = pd.merge(report, mrkt.drop("commodity",1), on="date")
sale_price_higher_than_market = full_report.sale_price > full_report.price