Transform Shape of a Pandas Dataframe -
i transform dataframe table below. similar reverse one-hot encoding, not same. there elegant way it?
from
to
df=pd.dataframe({'17-07-05': {3142: 1.0, 3214: np.nan}, '17-07-12': {3142: 1.0, 3214: np.nan}, '17-07-19': {3142: np.nan, 3214: np.nan}, 'website_id': {3142: 3142, 3214: 3214}})
pd.melt(df, 'website_id', var_name='date').sort_values('website_id') website_id date value 0 3142 17-07-05 1.0 2 3142 17-07-12 1.0 4 3142 17-07-19 nan 1 3214 17-07-05 nan 3 3214 17-07-12 nan 5 3214 17-07-19 nan
Comments
Post a Comment