Skip to content

Instantly share code, notes, and snippets.

@wesslen
Created October 27, 2021 14:36
Show Gist options
  • Select an option

  • Save wesslen/117705fdd4578a6076488f8c1e4d7e11 to your computer and use it in GitHub Desktop.

Select an option

Save wesslen/117705fdd4578a6076488f8c1e4d7e11 to your computer and use it in GitHub Desktop.
pandas columns to prodigy file formats
file_output = 'data/emails-hits.jsonl' # name of output file
(df_hits[['Message-ID','From','To','Subject','Body']]
.rename(columns={"Body": "text", "Message-ID": "id", "From": "from", "To": "to", "Subject":"subject"}) # optional rename
.groupby(['text']) # group_by text
.apply(lambda x: x[['id','from','to','subject']].to_dict(orient='list')) #what columns to nest
.reset_index()
.rename(columns={0:'meta'}) # rename nested meta
.to_json(file_output, orient='records',lines=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment