I am trying to separate a pandas dataframe column which has values like this -
My aim is to create a list of values for each "constraint" and put each value inside single quotes. This should be the expected output -
I have tried pandas groupby apply(list) but it's not working as expected. I was hoping to get a proper pandas list which has each of the values inside quotes and then separated by commas, however, its generating the below output (the values are separated by comma but quotes are only before first value and after last value).
Here is my code -
grouped_targets = target_table.groupby(['user_id', 'target_type'])['constraints'].apply(set).apply(list).reset_index()
grouped_targets.head()
And this is the output generated from my code-
What am I doing wrong?