I am new to pandas, I am trying to use group by and create a list of in a new column. I have 3 columns in my Dataframe and I created a 4th column(New_List) to create a list from another column like below: using the below code:
new_df = df.join(pd.Series(df.groupby(by='NO_ACCOUNTS').apply(lambda x: list(x.Bucket)), name="list_of_b"), on='NO_ACCOUNTS')
Account_Number Bucket Number_Transactions New_List
ABA APP 155 [APP]
ABC APP 1352 [APP]
AAA APP 90 [API,APP]
AAA API 5 [API,APP]
I am looking to get the desired output with 3 columns:
Account_Number Number_Transactions New_List
ABA 155 [APP]
ABC 1352 [APP]
AAA 95 [API,APP]