Skip to content

Instantly share code, notes, and snippets.

@drasch
Created October 4, 2013 20:36
Show Gist options
  • Save drasch/6832315 to your computer and use it in GitHub Desktop.
Save drasch/6832315 to your computer and use it in GitHub Desktop.
df = pd.DataFrame(np.random.randn(10000), index=range(0,10000), columns=['length'])
df.index.name = 'id'
df2 = pd.DataFrame.from_dict({'selector':randint(0,2, 20000), 'df_index': randint(1,10000,20000)})
# df_index is a foreign key into df.index
df['in_selector_0'] = np.asarray(np.where(df.reset_index().id.isin(df2[df2.selector.between(0,0.1)].df_index),'y', 'n'))
df.in_selector_0.value_counts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment