我有一个以下格式的数据集:
county area pop_2006 pop_2007 pop_2008
01001 275 1037 1052 1102
01003 394 2399 2424 2438
01005 312 1638 1647 1660
Run Code Online (Sandbox Code Playgroud)
我需要这样的格式:
county year pop area
01001 2006 1037 275
01001 2007 1052 275
01001 2008 1102 275
01003 2006 2399 394
01003 2007 2424 394
...
Run Code Online (Sandbox Code Playgroud)
我已经尝试了我能想到的pivot_table、stack、unstack、wide_to_long的每一种组合,但还没有成功。(显然我对 Python/pandas 基本上是文盲,所以请温柔点......)。