I have dataframe df:
col_name col_month col_value
abc 2021-01-31 233
abc 2021-02-28 784
abc 2021-03-31 7868
def 2021-02-28 3652
def 2021-03-31 344
def 2021-04-30 87
I need the result as:
col_name NAME col1 col2 col3
abc col_month 2021-01-31 2021-02-28 2021-03-31
abc col_value 233 784 7868
def col_month 2021-02-28 2021-03-31 2021-04-30
def col_value 3652 344 87
what i have tried so far using melt:
pd.melt(df, id_vars=['col_name'], var_name = 'NAME', value_name = 'VALUE')
this give the result:
col_name NAME VALUE
abc col_month 2021-01-31
abc col_month 2021-02-28
abc col_month 2021-03-31
def col_month 2021-02-28
def col_month 2021-03-31
def col_month 2021-04-30
abc col_value 233
abc col_value 784
abc col_value 7868
def col_value 3652
def col_value 344
def col_value 87
but i am not still able to get the desired result