我的数据看起来像这样:-
Month Year Value
Jan 2015 2.8
Jan 2015 2.0
Mar 2016 0.9
Feb 2015 3.1
Mar 2016 4.2
Feb 2015 2.1
Mar 2016 2.3
Feb 2015 1.1
Apr 2016 1.3
Apr 2016 0.5
现在,我想绘制折线图,但是通过使用此代码,我得到了此输出。 [以下
我使用的代码:-
df = rslt_bb.sort_values(by='Year')
trace = go.Scatter(
x = df["Year"],
y = df["Value"],
mode='markers+lines'
)
layout = go.Layout(
#title='Distribution by year',
xaxis=dict(title='Year'),
yaxis=dict(title='Value'),
showlegend=True
)
fig = dict(data=[trace], layout=layout)
offline.iplot(fig)
您需要创建datetime
对象才能绘制Time Series
。所以代替
x = df["Year"]
用途
x = pd.to_datetime(df.Year*100+df.Month, format='%Y%m')