Python pandas melting data to multiple columns and coulmn names in another column
问题 I have a dataframe which I want to melt the data into multiple target columns. The below code I used grp2 = pd.lreshape(grp1, cols.groupby(cols.str.split('_').str[1])).sort_values('ACCT_NAME') The above line I lose the column names grp2 = pd.melt(grp1 , id_vars = ['Client' , 'Industry'] , var_name = "H Year" , value_name = 'Count') The above line I dont get multiple target columns From DF Client INDUSTRY 1H2016_6MO 2H2016_6MO 1H2017_6MO 2H2017_6MO 1H2016_12MO 2H2016_12MO 1H2017_12MO 2H2017