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
Example: Deaths by Horsekicks The time series plot above of "Deaths by horsekick in Prussian cavalry corps, 1875-94" displays the number of annual deaths in each of these 20 years. In other words, one quantitative variable is examined over time.
Scatter. The Scatter view uses a scatter plot to display time series data. A scatter plot can have anything on the horizontal axis, in any transformation, and points are not connected or ordered. The scatter visualization maps each data point to X and Y coordinates.
A line graph is the simplest way to represent time series data.
In X-axis we should have a variable of DateTime. In Y-axis we can have the variable which we want to analyze with respect to time. plt. plot() method is used to plot the graph in matplotlib.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With