Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

python - How to plot a table using matplotlib

I have the following dataframe from pandas. I want to create a matplotlib table, something similar to this:

Zip Codes 2016  2017  2018  2019
2443       92.8  93.4 93.07 93.76
2445       94.9  94.4 95    95.13

This is the dataframe i have:

 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

How can i pivot the data and display it as above?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the pandas pivot method. Something like:

df.pivot(index="Zip Codes", columns="Year", values="Growth")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...