Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 845475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:27:29+00:00 2026-05-15T06:27:29+00:00

I’m in the process of trying to switch from R to Python (mainly issues

  • 0

I’m in the process of trying to switch from R to Python (mainly issues around general flexibility). With Numpy, matplotlib and ipython, I’ve am able to cover all my use cases save for merging ‘datasets’. I would like to simulate SQL’s join by clause (inner, outer, full) purely in python. R handles this with the ‘merge’ function.

I’ve tried the numpy.lib.recfunctions join_by, but it critical issues with duplicates along the ‘key’:


join_by(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2',
        defaults=None, usemask=True, asrecarray=False)

Join arrays r1 and r2 on key key.

The key should be either a string or a sequence of string corresponding
to the fields used to join the array.
An exception is raised if the key field cannot be found in the two input
arrays.

Neither r1 nor r2 should have any duplicates along key: the presence
of duplicates will make the output quite unreliable. Note that duplicates
are not looked for by the algorithm.

source: http://presbrey.mit.edu:1234/numpy.lib.recfunctions.html


Any pointers or help will be most appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:27:30+00:00Added an answer on May 15, 2026 at 6:27 am

    Suppose you represent the equivalent of a SQL table, in Python, as a list of dicts, all dicts having the same (assume string) keys (other representations, including those enabled by numpy, can be logically boiled down to an equivalent form). Now, an inner join is (again, from a logical point of view) a projection of their cartesian product — in the general case, taking a predicate argument on (which takes two arguments, one “record” [[dict]] from each table, and returns a true value if the two records need to be joined), a simple approach would be (using per-table prefixes to disambiguate, against the risk that the two tables might otherwise have homonimous “fields”):

    def inner_join(tab1, tab2, prefix1, prefix2, on):
      for r1 in tab1:
        for r2 in tab2:
          if on(r1, r2):
            row = dict((prefix1 + k1, v1) for k1, v1 in r1.items())
            row.update((prefix2 + k2, v2) for k2, v2 in r2.items())
            yield row
    

    Now, of course you don’t want to do it this way, because performance is O(M * N) — but, for the generality you’ve specified (“simulate SQL’s join by clause (inner, outer, full)”) there is really no alternative, because the ON clause of a JOIN is pretty unrestricted.

    For outer and full joins, you need in addition to keep info identifying which records [[from one or both tables]] have not been yielded yet, and otherwise yield — e.g. for a left join you’d add a bool, reset to yielded = False before the for r2 inner loop, set to True if the yield executes, and after the inner loop, if not yielded:, produce an artificial joined record (presumably using None to stand for NULL in place of the missing v2 values, since there’s no r2 to actually use for the purpose).

    To get any substantial efficiency improvements, you need to clarify what constraints you’re willing to abide on regarding the on predicate and the tables — we already know from your question that you can’t live with a unique constraint on either table’s keys, but there are many other constraints that could potentially help, and to have us guessing at what such constraints actually apply in your case would be a pretty unproductive endeavor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 468k
  • Answers 468k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's not reasonable to ask people not to point to… May 16, 2026 at 2:14 am
  • Editorial Team
    Editorial Team added an answer It's a language feature of C++ C++ (ISO 14882:2003) 6.6.3/3… May 16, 2026 at 2:14 am
  • Editorial Team
    Editorial Team added an answer I'm taking a shot in the dark here, it seems… May 16, 2026 at 2:14 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.