-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
merge_asof on multiple columns? #20369
Comments
Very actual |
I looked into this a little bit and by removing these checks, I was able to merge on multiple keys and it seems to work, also with |
mmm the checks seem pretty clear that it can only work with 1 key, wonder why but I guess there must be a reason! If you look into the tests for merge_asof they all use just 1 key per side. |
Hi, I also got same problem when trying to select multiple keys. Great if we can have a fix for this. |
I've just stumbled upon this issue as well. I wonder if it would be practical to allow for this? |
Hi, I have come across this issue as well. It will be great if we can fix for this. |
+1 on this, I think it would be a great enhancement if possible. |
how would this work? this seems like an impossible request take the OP as an example: you need some way to trade off 'closeness' in one field and 'closeness' in the second if there are no exact matches. I would suggest defining and calculating a common metric yourself. for example, the haversine distance between two lat/longs. of course, that would mean calculating the distance between every point possible, which kind of defeats the purpose of merge_asof what might be more helpful is some combination of regular merge and asof, e.g. exact match on one pair of fields, nearest match on another |
There is no need to calculate distance between EVERY point if one specifies tolerance criteria for separate merge keys. The common metric could be added as another parameter (function taking arbitrary number of arguments). |
Since the asof merge requires pre-sorted data, wouldn't a multi-key merge be the same as merging on a single column of sorted tuples? |
bump into this, and need this feature... |
If anyone has a good motivation example please indicate it with pseudo code and full inputs and outputs |
Bump here as well. I need this feature. Would love to know if there is a development since 2018. |
pandas is open source and all volunteer community contributions are how things are implemented |
It took me a bit to interpret the documentation, but as I understand it, what @tbaer-c7ks7s suggested:
Is already implemented using the The "real world time-series example" from the documentation makes this clear:
And I have also confirmed that |
I think the OP has a great use case, which is the same as mine; namely joining/snapping lat, lon coorinate pairs to a lat, lon coordinate grid. I think in the meantime, if it isn't possible, would adding some clearer documentation saying you can only join with a single column on |
Just to add another use case: I'm doing a metaheuristic search in a continuous hyperparameter space and I want to merge two experiments. Even though the experiment uses a subset of the hparams tried in the first experiment, because I used floats I can't use a normal join. |
Thank you very much for your work Pandas people! I have the error
pandas.errors.MergeError: can only asof on a key for left
when I run the code below:Problem description
it seems that
merge_asof
does not accept list of columns to merge on. Documentation seems to say that theleft_on
argument is a "label" and not a list.So maybe what I am asking is for an enhancement? It just seems weird that it can only merge on 1 column.
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: