使用Pandas DataReader绘制世界银行数据

2024-09-27 07:30:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试绘制我使用Pandas DataReader从世界银行导入的数据帧。但是当我画它的时候,它显示了一个奇怪的情节。年份列和x轴显示不正确。我该怎么办?谢谢

[The plot1

from pandas_datareader import wb
import datetime
ind = ['NY.GNP.PCAP.CD']
df = wb.download(indicator=ind, country='CHN', start=2000, end=2021)
df.head()
df.plot()

                NY.GNP.PCAP.CD
country year    
China   2020    10610
        2019    10390
        2018    9600
        2017    8740
        2016    8270

Tags: 数据importpandasdf绘制cdpcapcountry
1条回答
网友
1楼 · 发布于 2024-09-27 07:30:35
from pandas_datareader import wb
import pandas as pd
import matplotlib.pyplot as plt 

import datetime
ind = ['NY.GNP.PCAP.CD']
df = wb.download(indicator=ind, country='CHN', start=2000, end=2021)

然后可以使用pd.plotting.scatter_matrix()如下所示:

pd.plotting.scatter_matrix(df)
plt.show()

在输出中,您有如下直方图: enter image description here

相关问题 更多 >

    热门问题