我有以下来自panda的数据帧。我想创建一个matplotlib表,类似于以下内容:
Zip Codes 2016 2017 2018 2019
2443 92.8 93.4 93.07 93.76
2445 94.9 94.4 95 95.13
这是我拥有的数据帧:
Zip Codes,Year,Growth
2443,2016,92.8695652173913
2443,2017,93.3644859813084
2443,2018,93.07
2443,2019,93.76
2445,2016,94.84883720930233
2445,2017,94.43085106382979
2445,2018,94.99236641221374
2445,2019,95.13725490196079
2447,2016,94.85365853658537
2447,2017,94.4171270718232
2447,2018,93.65760869565217
2447,2019,94.12021857923497
如何将数据透视并显示为如上所述?
使用pandas pivot方法。类似于:
df.pivot(index="Zip Codes", columns="Year", values="Growth")