pandas, melt, unmelt preserve index

后端 未结 3 790
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 09:10

I\'ve got a table of clients (coper) and asset allocation (asset)

A = [[1,2],[3,4],[5,6]]
idx = [\'coper1\',\'coper2\',\'coper3\']
cols = [\'asset1\',\'asset         


        
3条回答
  •  死守一世寂寞
    2020-12-09 10:10

    set the ignore_index to be False to preserve the index, e.g.

    df = df.melt(var_name=‘species’, value_name=‘height’, ignore_index = False)
    

提交回复
热议问题