Skip to content

Instantly share code, notes, and snippets.

@conormm
Created May 18, 2021 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conormm/929d16832efab76af0434ca3a90d8b1f to your computer and use it in GitHub Desktop.
Save conormm/929d16832efab76af0434ca3a90d8b1f to your computer and use it in GitHub Desktop.
(tidy_docs
.groupby("doc_id")
.apply(lambda x: x.assign(
prev_token = lambda x: x.token.shift(1),
next_token = lambda x: x.token.shift(-1))
)
.reset_index(drop=True)
.query("tag == 'POS'")
.loc[:, ["doc_id", "prev_token", "token", "next_token"]]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment