0

在下面的 MWE 中,我的year变量在 x 轴上显示为 0 到 6,而不是实际的年份数。为什么是这样?

import pandas as pd
from pandas_datareader import wb
from ggplot import *

dat = wb.download(
    indicator=['BX.KLT.DINV.CD.WD', 'BX.KLT.DINV.WD.GD.ZS'],
    country='CN', start=2005, end=2011)
dat.reset_index(inplace=True)

print ggplot(aes(x='year', y='BX.KLT.DINV.CD.WD'),
       data=dat) + \
    geom_line() + theme_bw()
4

1 回答 1

1

您需要做的就是将year列从 an转换object dtypedatetime64

dat['year'] = pd.to_datetime(dat['year'])

在此处输入图像描述

于 2016-02-25T07:29:17.780 回答