Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - Plotting a time series?

I'm really new to using python as a data analysis tool, and it's my first time ever dealing with time series. I have a data set which has dates in the first column, and a "result" integer which is either 1 or 0. The date column was successfully converted to a time object. I tried to plot the values directly using matplotlib's plot function, but that did not work.. Sample:

    Date       Result
2017-01-06     0.0
2017-01-06     1.0
2017-01-06     0.0
2017-01-07     0.0
2017-01-07     0.0

I tried using df.plot(), but the resulting plot has very undesirable results.

What I want at the end of the day is dates on the x axis, and the "result" on the y axis. Where am I going wrong? What's wrong with what I'm doing? EDIT: Here's the graph

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Please use

df.set_index('Date').plot()

or

df.plot(x='Date', y='Result')

because of the plot by default use index of df as the x-axis, so you should set the 'Date' column as the index, or specify which column to use as the x-axis.

see more at pandas.DataFrame.plot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...