Skip to content

Accesing a complete series when using ApplyByCols #106

Answered by shaypal5
vecorro asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @vecorro !

Sorry for the extremely belated response.
I still wanted to address this, for future users.

Ok, if we first define this:

class SentenceClipper:
  def __init__(self, lim: int) -> None:
    self.lim = lim
  def __call__(self, text: str):
    words = text.split(' ')
    words = words[:self.lim]
    return ' '.join(words)

class SentenceColumnClipper(pdp.PdPipelineStage):

  def _prec(self, df: pd.DataFrame) -> bool:
    return 'text' in df.columns

  def _transform(self, df: pd.DataFrame, verbose:bool) -> pd.DataFrame:
    lim = self.application_context['nwords_lim']
    print(f'Calcualted word limit: {lim}')
    clipper = SentenceClipper(lim=lim)
    res_df = df.copy()
    re…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by shaypal5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #60 on July 03, 2022 15:09.