Skip to content

Instantly share code, notes, and snippets.

@rib3ye
Last active June 7, 2018 15:43
Show Gist options
  • Save rib3ye/4b7daa31413e8f765ea4865e0c7fdfe1 to your computer and use it in GitHub Desktop.
Save rib3ye/4b7daa31413e8f765ea4865e0c7fdfe1 to your computer and use it in GitHub Desktop.
Python Join errors when using the datascience module

The join method in the datascience module is not the join string method.

def state(state1, state2):
    state1_table = murder_rates.where('State', state1).drop('State', 'Population').relabeled(1, 'Murder rate in {}'.format(state1))
    state2_table = murder_rates.where('State', state2).drop('State', 'Population').relabeled(1, 'Murder rate in {}'.format(state2))
    
    s1_s2 = state1.join('Year', state2, 'Year')

state('California', 'New York')

Occasionally you may see the following error when trying to join two tables with a common column name.

TypeError: join() takes exactly one argument (3 given)

However, if you run help(table1.join), suddenly you see some unexpected advice:

Help on built-in function join:

join(...) method of numpy.str_ instance
    S.join(iterable) -> str
    
    Return a string which is the concatenation of the strings in the
    iterable.  The separator between elements is S.

If this happens again, check the table name you're running join on. Very likely you're running the method on the wrong scalar value. Make sure the object is actually a table object. You're welcome, future me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment