0

I am trying to plot a time-series data hourly.

                         col1      col2   col3      col4    col5    col6    col7
DateTime                            
2018-09-26 00:00:00     25502921    0   44.677500   0.0     0.0     0.0     0
2018-09-26 01:00:00     25502921    0   44.677500   0.0     0.0     0.0     0
2018-09-26 02:00:00     25502921    0   44.677500   0.0     0.0     0.0     0
2018-09-26 03:00:00     25502921    0   44.677500   0.0     0.0     0.0     0

As I tried to use hourly.plot(x=hourly.index, y='col1') this is the following trace i get.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-77-63f4f82f4d4e> in <module>
----> 1 hourly.plot(x=hourly.index, y='col1')

~/.local/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, *args, **kwargs)
    810                 if is_integer(x) and not data.columns.holds_integer():
    811                     x = data_cols[x]
--> 812                 elif not isinstance(data[x], ABCSeries):
    813                     raise ValueError("x must be a label or position")
    814                 data = data.set_index(x)

~/.local/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2804             if is_iterator(key):
   2805                 key = list(key)
-> 2806             indexer = self.loc._get_listlike_indexer(key, axis=1, raise_missing=True)[1]
   2807 
   2808         # take() does not accept boolean indexers

~/.local/lib/python3.6/site-packages/pandas/core/indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
   1551 
   1552         self._validate_read_indexer(
-> 1553             keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
   1554         )
   1555         return keyarr, indexer

~/.local/lib/python3.6/site-packages/pandas/core/indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
   1638             if missing == len(indexer):
   1639                 axis_name = self.obj._get_axis_name(axis)
-> 1640                 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
   1641 
   1642             # We (temporarily) allow for some missing keys with .loc, except in

KeyError: "None of [DatetimeIndex(['2018-09-26 00:00:00', '2018-09-26 01:00:00',\n               '2018-09-26 02:00:00', '2018-09-26 03:00:00',\n               '2018-09-26 04:00:00', '2018-09-26 05:00:00',\n               '2018-09-26 06:00:00', '2018-09-26 07:00:00',\n               '2018-09-26 08:00:00', '2018-09-26 09:00:00',\n               '2018-09-26 10:00:00', '2018-09-26 11:00:00',\n               '2018-09-26 12:00:00', '2018-09-26 13:00:00',\n               '2018-09-26 14:00:00', '2018-09-26 15:00:00',\n               '2018-09-26 16:00:00', '2018-09-26 17:00:00',\n               '2018-09-26 18:00:00', '2018-09-26 19:00:00',\n               '2018-09-26 20:00:00', '2018-09-26 21:00:00',\n               '2018-09-26 22:00:00', '2018-09-26 23:00:00'],\n              dtype='datetime64[ns]', name='DateTime', freq='H')] are in the [columns]"

Please help me figure out the problem.

raaj
  • 403
  • 1
  • 5
  • 17

1 Answers1

0

Drop the index, you should just do:

hourly.plot( y='col1')

and pandas will plot the y columns against the index.

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74