Created
October 27, 2021 14:36
-
-
Save wesslen/117705fdd4578a6076488f8c1e4d7e11 to your computer and use it in GitHub Desktop.
pandas columns to prodigy file formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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