[Python] How to merge two dataframes based on condition

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have 2 dataframes:

    df1:

    BA Product FixedPrice Vintage DeliveryPeriod
    A foo 10.00 Vintage 2025 Mar25
    B foo 11.00 Vintage 2025 Dec25
    B foo 12.00 Vintage 2024 Sep25
    C bar 2.00 None Nov25


    df2:

    Service DeliveryPeriod FloatPrice
    ICE - Vintage 2025 Mar25 5.00
    ICE - Vintage 2025 Dec25 4.00
    ICE - Vintage 2024 Sep25 6.00
    ICE - Vintage 2023 Nov25 1.00


    How can I get a result like this:

    BA Product FixedPrice Vintage DeliveryPeriod FloatPrice
    A foo 10.00 Vintage 2025 Mar25 5.00
    B foo 11.00 Vintage 2025 Dec25 4.00
    B foo 12.00 Vintage 2024 Sep25 6.00
    C bar 2.00 None Nov25 0.00


    I was going to use merge but the columns don't match and neither do the values. I need to get the float price based on if Service contains the value from Vintage and matches the delivery period.

    Continue reading...

Compartilhe esta Página