Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join between Polars dataframes with inequality conditions #6753

Closed
2 tasks done
andrearota opened this issue Feb 9, 2023 · 2 comments
Closed
2 tasks done

Join between Polars dataframes with inequality conditions #6753

andrearota opened this issue Feb 9, 2023 · 2 comments

Comments

@andrearota
Copy link

Research

  • I have searched the above polars tags on Stack Overflow for similar questions.

  • I have asked my usage related question on Stack Overflow.

Link to question on Stack Overflow

https://stackoverflow.com/questions/75399353/join-between-polars-dataframes-with-inequality-conditions

Question about Polars

I would like to do a join between two dataframes, using as join condition an inequality condition, i.e. greater than.

Given two dataframes, I would like to get the result equivalent to the SQL written below.

stock_market_value = pl.DataFrame(
    {
        "date": [date(2022, 1, 1), date(2022, 2, 1), date(2022, 3, 1)],
        "price": [10.00, 12.00, 14.00]

    }
)

my_stock_orders = pl.DataFrame(
    {
        "date": [date(2022, 1, 15), date(2022, 2, 15)],
        "quantity": [2, 5] 
    }
)

I have read that Polars supports join of type asof, but I don't think it applies to my case (maybe putting tolerance equal to infinity?).

SELECT m.date, m.price * o.quantity AS portfolio_value
FROM stock_market_value m LEFT JOIN my_stock_orders o
  ON m.date >= o.date

Thanks!

@ritchie46
Copy link
Member

I answered on SO

@andrearota
Copy link
Author

andrearota commented Feb 10, 2023

Hi @ritchie46, thanks. I read your answer, but I believe it does not apply. A SO user added an example to clarify the expected result to the original question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants