Say I have a dataframe
I want to re-shape it AND concatenate the strings
I can reshape it using melt but I lose the description. I've tried transform but no luck Any ideas?
Code:
import pandas as pd
x = [['a', 'Electronics', 'TV', '42" plasma'], ['a', 'Electronics', 'TV', '36" LCD'], ['a', 'Electronics', 'hifi', 'cd player'], ['a', 'Electronics', 'hifi', 'record player'], ['b', 'Sports', 'Soccer', 'mens trainers'], ['b', 'Sports', 'Soccer', 'womens trainers'], ['b', 'Sports', 'golf', '9 iron']]
df = pd.DataFrame(x, columns =['id', 'category','sub_category','description'])
y = pd.melt(df, id_vars=['id'],value_vars=['category','sub category'])['description'].transform(lambda x : ' '.join(x))

