Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

=================== Task1 ========================= Target: Use the SQL-like operation in polars.DataFrame (the class of the variable 'train') to turn the Original Format into Sentence Format as

=================== Task1 ========================= Target: Use the SQL-like operation in polars.DataFrame (the class of the variable 'train') to turn the Original Format into Sentence Format as below session type sentence --- --- --- i32 list[u8] list[i32] 0 [0, 0, 0] [1517085, 1563459, 161938] 1 [1, 0, 0] [424964, 1492293, 497868] 2 [0, 0, 0] [763743, 137492, 672473] 3 [1, 0, 1] [1425967, 1425967, 925352] 4 [0, 0, 0] [613619, 298827, 479396] Main Points: 1. You need to group aids and types using session as index. 2. Sort the groups by session number 3. Rename 'aid' as 'sentence' 4. Just remain the coloums of session, type and sentence 5. The variable name should be 'sentences_df' """ # Add your code here sentences_df = train.group_by(['session'])\ .agg(pl.col('type'), pl.col('aid').alias("sentence")).sort(by=['session'])\ .select(['session', 'type', 'sentence'])

print('Sentences Format: ', sentences_df.head(), ' ')

sentences = sentences_df['sentence'].to_list() del sentences_df gc.collect() # garbage collect return sentences

def TrainValidationSplit(): train = pl.read_parquet('./input/test/train.parquet') """

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions