0

I'm applying this to a more extensive data set, but the idea is the same. Let me elaborate.

I have the following data frame:

list = [('a' , 'X', 'good '),
       ('a', 'Y', 'ok '),
       ('b', 'Y', 'nice '),
       ('b', 'Z', 'bad '),
       ('c', 'X', 'ugly ')]

df = pd.DataFrame(list, columns = ['user', 'item', 'text'])

I group all the user text into one column, and I do the same for the items. (I've completed this step)

This creates two new data frames called df_user and df_item

df_user = **user | text**
            'a'  | good ok
            'b'  | nice bad
            'c'  | ugly

df_item = **item | text**
            'X'  | good ugly
            'Y'  | ok nice
            'Z'  | bad

And the final step would be adding the text from df_user and df_item to df.

df should look like this:

df =  ** user | item | user_text | item_text**
           a  |   X  | good ok   | good ugly
           a  |   Y  | good ok   | ok nice
           b  |   Y  | nice bad  | ok nice
           b  |   Z  | nice bad  | bad
           c  |   X  | ugly      | good ugly

My question is, how to add the grouped text data from df_user and df_item into df, as shown above?

0 Answers0