1

In Python I am trying to use the following command to get timestamp info on my plot. I've imported the proper packages pandas and pylab. The data is all cleaned as well.

data.plot(x=data.timestamp, style=".-")

I keep getting a massive error with lots of different things. I am following along to https://www.youtube.com/watch?v=5XGycFIe8qE and it comes at 38 minutes. Here is the error I get: It's massive

Traceback (most recent call last): File "", line 1, in data.plot(x=data.timestamp, style=".-") File "C:\Python3\lib\site-packages\pandas\plotting_core.py", line 2673, in call sort_columns=sort_columns, **kwds) File "C:\Python3\lib\site-packages\pandas\plotting_core.py", line 1900, in plot_frame **kwds) File "C:\Python3\lib\site-packages\pandas\plotting_core.py", line 1727, in _plot plot_obj.generate() File "C:\Python3\lib\site-packages\pandas\plotting_core.py", line 260, in generate self._post_plot_logic_common(ax, self.data) File "C:\Python3\lib\site-packages\pandas\plotting_core.py", line 395, in _post_plot_logic_common self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize) File "C:\Python3\lib\site-packages\pandas\plotting_core.py", line 468, in _apply_axis_properties labels = axis.get_majorticklabels() + axis.get_minorticklabels() File "C:\Python3\lib\site-packages\matplotlib\axis.py", line 1188, in get_majorticklabels ticks = self.get_major_ticks() File "C:\Python3\lib\site-packages\matplotlib\axis.py", line 1339, in get_major_ticks numticks = len(self.get_major_locator()()) File "C:\Python3\lib\site-packages\matplotlib\dates.py", line 1054, in call self.refresh() File "C:\Python3\lib\site-packages\matplotlib\dates.py", line 1074, in refresh dmin, dmax = self.viewlim_to_dt() File "C:\Python3\lib\site-packages\matplotlib\dates.py", line 832, in viewlim_to_dt return num2date(vmin, self.tz), num2date(vmax, self.tz) File "C:\Python3\lib\site-packages\matplotlib\dates.py", line 441, in num2date return _from_ordinalf(x, tz) File "C:\Python3\lib\site-packages\matplotlib\dates.py", line 256, in _from_ordinalf dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC) ValueError: ordinal must be >= 1

derrik bosse
  • 23
  • 1
  • 5
  • Can you share the data? – Scott Boston Nov 22 '17 at 21:47
  • I woudl guess it is the same issue as [this one](https://stackoverflow.com/questions/47404653/pandas-0-21-0-timestamp-compatibility-issue-with-matplotlib). – ImportanceOfBeingErnest Nov 22 '17 at 22:05
  • The dataset is here: https://github.com/QCaudron/pydata_pandas/tree/master/data coffees.csv. I had to delete null values and change the datatypes of the timestamp and number of coffees to datetime and integer, respectively. I can view it in a plot using pylab But i want to add the timestamp element as my x value. – derrik bosse Nov 22 '17 at 23:52

1 Answers1

1

I had a similar issue and I believe it is a version issue with pandas and the Jupyter Notebook that are different from what Quentin is using in his examples here: https://github.com/QCaudron/pydata_pandas and what you, and I, are using.

Try this:

data.plot('timestamp', style='.-')

or

data.plot(x='timestamp', style='.-')

Per the pandas docs https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html either a label or position should work.

DataFrame
x : label or position, default None
y : label or position, default None
Allows plotting of one column versus another

TechSolX
  • 11
  • 1
  • 2