I've got a data frame whose first 5 elements look like this:
I have deleted all the null values from this dataframe. Here's the data types of each column:
Later, when I tried to get a plot by using
data.plot(x=data.timestamp, style='.-')
It shows up this error:
KeyError Traceback (most recent call last)
<ipython-input-48-e11e322ec19a> in <module>
4
5 # data.coffees.plot(x=data.timestamp, style='.-')
----> 6 data.plot(x=data.timestamp, style='.-')
7 # import matplotlib.pyplot as plt
8 # plt.plot(x=data.timestamp, y=data.coffees, style=".-")
~/Softwares-and-tools/Anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2939 fontsize=fontsize, colormap=colormap, table=table,
2940 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2941 sort_columns=sort_columns, **kwds)
2942 __call__.__doc__ = plot_frame.__doc__
2943
~/Softwares-and-tools/Anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
1975 yerr=yerr, xerr=xerr,
1976 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1977 **kwds)
1978
1979
~/Softwares-and-tools/Anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1764 if is_integer(x) and not data.columns.holds_integer():
1765 x = data_cols[x]
-> 1766 elif not isinstance(data[x], ABCSeries):
1767 raise ValueError("x must be a label or position")
1768 data = data.set_index(x)
~/Softwares-and-tools/Anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
2680 if isinstance(key, (Series, np.ndarray, Index, list)):
2681 # either boolean or fancy integer index
-> 2682 return self._getitem_array(key)
2683 elif isinstance(key, DataFrame):
2684 return self._getitem_frame(key)
~/Softwares-and-tools/Anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in _getitem_array(self, key)
2724 return self._take(indexer, axis=0)
2725 else:
-> 2726 indexer = self.loc._convert_to_indexer(key, axis=1)
2727 return self._take(indexer, axis=1)
2728
~/Softwares-and-tools/Anaconda3/lib/python3.6/site-packages/pandas/core/indexing.py in _convert_to_indexer(self, obj, axis, is_setter)
1325 if mask.any():
1326 raise KeyError('{mask} not in index'
-> 1327 .format(mask=objarr[mask]))
1328
1329 return com._values_from_object(indexer)
KeyError: "['2011-10-03T08:22:00.000000000' '2011-10-04T11:48:00.000000000'\n '2011-10-05T10:47:00.000000000' '2011-10-05T13:15:00.000000000'\n '2011-10-06T07:21:00.000000000' '2011-10-06T10:04:00.000000000'\n '2011-10-06T12:14:00.000000000' '2011-10-06T12:49:00.000000000'\n '2011-10-06T14:52:00.000000000' '2011-10-07T07:34:00.000000000'\n '2011-10-07T08:37:00.000000000' '2011-10-07T11:09:00.000000000'\n '2011-10-07T13:14:00.000000000' '2011-10-07T15:20:00.000000000'\n '2011-10-07T16:50:00.000000000' '2011-10-09T16:53:00.000000000'\n '2011-10-10T07:29:00.000000000' '2011-10-10T10:13:00.000000000'\n '2011-10-10T13:41:00.000000000' '2011-10-10T14:02:00.000000000'\n '2011-10-10T15:23:00.000000000' '2011-10-11T14:09:00.000000000'\n '2011-10-12T08:11:00.000000000' '2011-10-12T09:57:00.000000000'\n '2011-10-12T10:06:00.000000000' '2011-10-12T12:01:00.000000000'\n '2011-10-12T12:30:00.000000000' '2011-10-12T13:56:00.000000000'\n '2011-10-13T09:10:00.000000000' '2011-10-13T10:52:00.000000000'\n '2011-10-13T11:04:00.000000000' '2011-10-13T14:41:00.000000000'\n '2011-10-13T15:06:00.000000000' '2011-10-13T15:45:00.000000000'\n '2011-10-13T15:58:00.000000000' '2011-10-14T09:02:00.000000000'\n '2011-10-14T10:02:00.000000000' '2011-10-14T14:07:00.000000000'\n '2011-10-17T09:24:00.000000000' '2011-10-17T11:19:00.000000000'\n '2011-10-17T14:05:00.000000000' '2011-10-18T09:20:00.000000000'\n '2011-10-18T09:39:00.000000000' '2011-10-18T11:32:00.000000000'\n '2011-10-18T12:54:00.000000000' '2011-10-19T09:15:00.000000000'\n '2011-10-19T09:31:00.000000000' '2011-10-19T14:08:00.000000000'\n '2011-10-19T15:11:00.000000000' '2011-10-20T13:01:00.000000000'\n '2011-10-20T15:59:00.000000000' '2011-10-21T10:39:00.000000000'\n '2011-10-21T13:15:00.000000000' '2011-10-21T15:09:00.000000000'\n '2011-10-24T09:51:00.000000000' '2011-10-24T10:15:00.000000000'\n '2011-10-24T10:21:00.000000000' '2011-10-24T14:32:00.000000000'\n '2011-10-25T07:54:00.000000000' '2011-10-25T09:37:00.000000000'\n '2011-10-25T14:30:00.000000000' '2011-10-25T17:52:00.000000000'\n '2011-10-26T09:15:00.000000000' '2011-10-26T09:42:00.000000000'\n '2011-10-26T11:59:00.000000000' '2011-10-26T13:38:00.000000000'\n '2011-10-27T08:03:00.000000000' '2011-10-27T11:14:00.000000000'\n '2011-10-27T13:51:00.000000000' '2011-10-28T13:33:00.000000000'\n '2011-10-31T10:58:00.000000000' '2011-10-31T11:00:00.000000000'\n '2011-10-31T13:58:00.000000000' '2011-10-31T14:35:00.000000000'\n '2011-11-01T08:21:00.000000000' '2011-11-01T09:33:00.000000000'\n '2011-11-01T10:13:00.000000000' '2011-11-01T15:07:00.000000000'\n '2011-11-01T15:19:00.000000000' '2011-11-02T10:56:00.000000000'\n '2011-11-03T09:52:00.000000000' '2011-11-04T10:41:00.000000000'\n '2011-11-04T13:22:00.000000000' '2011-11-08T13:32:00.000000000'\n '2011-11-08T15:08:00.000000000' '2011-11-09T12:09:00.000000000'\n '2011-11-09T13:57:00.000000000' '2011-11-10T10:26:00.000000000'\n '2011-11-10T15:36:00.000000000' '2011-11-10T15:52:00.000000000'\n '2011-11-11T10:27:00.000000000' '2011-11-11T12:19:00.000000000'\n '2011-11-11T13:29:00.000000000' '2011-11-14T10:53:00.000000000'\n '2011-11-14T19:21:00.000000000' '2011-11-15T10:32:00.000000000'\n '2011-11-15T15:04:00.000000000' '2011-11-15T16:00:00.000000000'\n '2011-11-16T09:24:00.000000000' '2011-11-16T09:58:00.000000000'\n '2011-11-16T12:57:00.000000000' '2011-11-17T11:24:00.000000000'\n '2011-11-17T13:59:00.000000000' '2011-11-18T11:15:00.000000000'\n '2011-11-18T16:05:00.000000000' '2011-11-20T14:20:00.000000000'\n '2011-11-21T09:21:00.000000000' '2011-11-21T10:06:00.000000000'\n '2011-11-21T11:34:00.000000000' '2011-11-21T11:40:00.000000000'\n '2011-11-21T14:07:00.000000000' '2011-11-23T09:33:00.000000000'\n '2011-11-23T09:45:00.000000000' '2011-11-23T12:31:00.000000000'\n '2011-11-24T11:27:00.000000000' '2011-11-24T13:33:00.000000000'\n '2011-11-24T14:13:00.000000000' '2011-11-24T15:00:00.000000000'\n '2011-11-28T09:41:00.000000000' '2011-11-30T13:20:00.000000000'\n '2011-12-01T11:12:00.000000000' '2011-12-03T17:02:00.000000000'\n '2011-12-05T14:53:00.000000000' '2011-12-06T10:36:00.000000000'\n '2011-12-06T11:29:00.000000000' '2011-12-06T13:57:00.000000000'\n '2011-12-07T10:37:00.000000000' '2011-12-07T11:33:00.000000000'\n '2011-12-07T15:02:00.000000000' '2011-12-08T13:56:00.000000000'\n '2011-12-09T10:32:00.000000000' '2011-12-09T15:47:00.000000000'\n '2011-12-09T17:29:00.000000000' '2011-12-12T09:30:00.000000000'\n '2011-12-12T13:42:00.000000000' '2011-12-13T10:08:00.000000000'\n '2011-12-13T13:32:00.000000000' '2011-12-13T13:36:00.000000000'\n '2011-12-13T15:09:00.000000000' '2011-12-19T12:09:00.000000000'\n '2012-01-11T14:42:00.000000000' '2012-01-11T17:13:00.000000000'\n '2012-01-13T10:31:00.000000000' '2012-01-13T14:59:00.000000000'\n '2012-01-16T09:58:00.000000000' '2012-01-16T11:58:00.000000000'\n '2012-01-16T13:51:00.000000000' '2012-01-16T15:28:00.000000000'\n '2012-01-18T11:14:00.000000000' '2012-01-18T14:28:00.000000000'\n '2012-01-18T18:02:00.000000000' '2012-01-20T15:11:00.000000000'\n '2012-01-21T13:48:00.000000000' '2012-01-23T11:51:00.000000000'\n '2012-01-23T13:15:00.000000000' '2012-01-24T10:29:00.000000000'\n '2012-01-25T09:44:00.000000000' '2012-01-25T10:03:00.000000000'\n '2012-01-26T10:18:00.000000000' '2012-01-26T13:02:00.000000000'\n '2012-01-27T10:33:00.000000000' '2012-01-27T11:01:00.000000000'\n '2012-01-27T14:23:00.000000000' '2012-01-28T13:35:00.000000000'\n '2012-01-30T09:02:00.000000000' '2012-01-30T10:05:00.000000000'\n '2012-01-30T13:30:00.000000000' '2012-02-01T09:21:00.000000000'\n '2012-02-01T12:31:00.000000000' '2012-02-01T13:30:00.000000000'\n '2012-02-01T16:21:00.000000000' '2012-02-02T10:10:00.000000000'\n '2012-02-02T13:36:00.000000000' '2012-02-03T12:24:00.000000000'\n '2012-02-03T15:38:00.000000000' '2012-02-04T11:48:00.000000000'\n '2012-02-04T14:55:00.000000000' '2012-02-05T13:40:00.000000000'\n '2012-02-05T15:33:00.000000000' '2012-02-06T07:45:00.000000000'\n '2012-02-06T10:55:00.000000000' '2012-02-06T11:34:00.000000000'\n '2012-02-06T12:42:00.000000000' '2012-02-06T17:50:00.000000000'\n '2012-02-08T11:17:00.000000000' '2012-02-10T07:44:00.000000000'\n '2012-02-10T12:52:00.000000000' '2012-02-10T16:32:00.000000000'\n '2012-02-11T12:35:00.000000000' '2012-02-12T13:45:00.000000000'\n '2012-02-13T16:31:00.000000000' '2012-02-17T13:38:00.000000000'\n '2012-02-19T15:29:00.000000000' '2012-02-20T12:13:00.000000000'\n '2012-02-20T17:12:00.000000000' '2012-02-21T08:49:00.000000000'\n '2012-02-22T09:54:00.000000000' '2012-02-22T13:23:00.000000000'\n '2012-02-22T16:05:00.000000000' '2012-02-22T16:08:00.000000000'\n '2012-02-23T15:57:00.000000000' '2012-02-24T13:44:00.000000000'\n '2012-02-25T16:39:00.000000000' '2012-02-27T08:42:00.000000000'\n '2012-02-27T15:35:00.000000000' '2012-02-28T11:13:00.000000000'\n '2012-02-29T09:27:00.000000000' '2012-02-29T12:57:00.000000000'\n '2012-03-01T10:07:00.000000000' '2012-03-01T14:24:00.000000000'\n '2012-03-02T15:13:00.000000000' '2012-03-04T15:07:00.000000000'\n '2012-03-06T11:13:00.000000000' '2012-03-07T12:50:00.000000000'\n '2012-03-08T12:59:00.000000000' '2012-03-09T12:45:00.000000000'\n '2012-03-12T10:17:00.000000000' '2012-03-12T12:07:00.000000000'\n '2012-03-12T17:28:00.000000000' '2012-04-04T09:48:00.000000000'\n '2012-04-04T11:12:00.000000000' '2012-04-04T13:33:00.000000000'\n '2012-04-04T17:00:00.000000000' '2012-04-04T17:02:00.000000000'\n '2012-04-05T10:39:00.000000000' '2012-04-05T11:59:00.000000000'\n '2012-04-10T09:51:00.000000000' '2012-04-10T10:45:00.000000000'\n '2012-04-10T13:55:00.000000000' '2012-04-11T11:37:00.000000000'\n '2012-04-26T16:45:00.000000000' '2012-04-26T17:59:00.000000000'\n '2012-04-27T11:03:00.000000000' '2012-04-27T13:16:00.000000000'\n '2012-04-30T08:58:00.000000000' '2012-04-30T13:15:00.000000000'\n '2012-04-30T14:54:00.000000000' '2012-05-01T14:11:00.000000000'\n '2012-05-02T12:00:00.000000000' '2012-05-02T13:25:00.000000000'\n '2012-05-03T12:14:00.000000000' '2012-05-03T13:13:00.000000000'\n '2012-05-04T11:08:00.000000000' '2012-05-07T10:17:00.000000000'\n '2012-05-07T12:56:00.000000000' '2012-05-07T13:31:00.000000000'\n '2012-05-07T18:20:00.000000000' '2012-05-08T11:34:00.000000000'\n '2012-05-08T11:47:00.000000000' '2012-05-09T12:54:00.000000000'\n '2012-05-09T14:10:00.000000000' '2012-05-09T16:55:00.000000000'\n '2012-05-10T12:12:00.000000000' '2012-05-10T15:44:00.000000000'\n '2012-05-10T17:59:00.000000000' '2012-05-11T15:40:00.000000000'\n '2012-05-12T09:50:00.000000000' '2012-05-14T10:02:00.000000000'\n '2012-05-14T12:23:00.000000000' '2012-05-14T15:27:00.000000000'\n '2012-05-15T09:07:00.000000000' '2012-05-15T09:19:00.000000000'\n '2012-05-15T13:06:00.000000000' '2012-05-15T13:42:00.000000000'\n '2012-05-16T09:17:00.000000000' '2012-05-16T10:25:00.000000000'\n '2012-05-16T13:24:00.000000000' '2012-05-16T16:05:00.000000000'\n '2012-05-16T16:57:00.000000000' '2012-05-17T09:22:00.000000000'\n '2012-05-17T13:02:00.000000000' '2012-05-17T14:25:00.000000000'\n '2012-05-17T18:48:00.000000000' '2012-05-18T09:19:00.000000000'\n '2012-05-18T12:57:00.000000000' '2012-05-18T13:14:00.000000000'\n '2012-05-20T14:00:00.000000000' '2012-05-21T09:15:00.000000000'\n '2012-05-21T14:40:00.000000000' '2012-05-22T10:08:00.000000000'\n '2012-05-22T13:23:00.000000000' '2012-05-24T09:23:00.000000000'\n '2012-05-24T13:23:00.000000000' '2012-05-24T15:51:00.000000000'\n '2012-05-25T09:19:00.000000000' '2012-05-25T11:10:00.000000000'\n '2012-05-25T11:55:00.000000000' '2012-05-25T12:34:00.000000000'\n '2012-05-26T15:40:00.000000000' '2012-05-28T09:16:00.000000000'\n '2012-05-28T12:57:00.000000000' '2012-05-28T19:24:00.000000000'\n '2012-05-29T11:07:00.000000000' '2012-05-29T13:29:00.000000000'\n '2012-05-31T09:09:00.000000000' '2012-05-31T12:41:00.000000000'\n '2012-05-31T17:24:00.000000000' '2012-06-01T09:20:00.000000000'\n '2012-06-01T13:27:00.000000000' '2012-06-01T18:50:00.000000000'\n '2012-06-04T08:42:00.000000000' '2012-06-04T12:24:00.000000000'\n '2012-06-04T13:25:00.000000000' '2012-06-04T15:09:00.000000000'\n '2012-06-05T15:29:00.000000000' '2012-06-05T16:56:00.000000000'\n '2012-06-06T09:18:00.000000000' '2012-06-06T10:20:00.000000000'\n '2012-06-06T13:33:00.000000000' '2012-06-06T15:42:00.000000000'\n '2012-06-07T08:44:00.000000000' '2012-06-07T09:30:00.000000000'\n '2012-06-07T13:36:00.000000000' '2012-06-07T17:32:00.000000000'\n '2012-06-07T19:11:00.000000000' '2012-06-08T09:53:00.000000000'\n '2012-06-08T10:04:00.000000000' '2012-06-08T11:55:00.000000000'\n '2012-06-11T09:13:00.000000000' '2012-06-11T12:41:00.000000000'\n '2012-06-11T13:25:00.000000000' '2012-06-11T14:59:00.000000000'\n '2012-06-11T16:01:00.000000000' '2012-06-11T19:08:00.000000000'\n '2012-06-12T08:15:00.000000000' '2012-06-15T12:40:00.000000000'\n '2012-06-15T12:43:00.000000000' '2012-06-17T13:43:00.000000000'\n '2012-06-17T17:44:00.000000000' '2012-06-18T09:12:00.000000000'\n '2012-06-18T13:02:00.000000000' '2012-06-18T17:55:00.000000000'\n '2012-06-19T11:28:00.000000000' '2012-06-20T12:49:00.000000000'\n '2012-06-26T11:18:00.000000000' '2012-06-26T15:05:00.000000000'\n '2012-06-26T19:35:00.000000000' '2012-06-27T12:06:00.000000000'\n '2012-06-28T11:46:00.000000000' '2012-06-28T17:42:00.000000000'\n '2012-06-29T09:17:00.000000000' '2012-06-29T16:47:00.000000000'\n '2012-07-02T12:12:00.000000000' '2012-07-02T17:09:00.000000000'\n '2012-07-03T12:17:00.000000000' '2012-07-03T16:09:00.000000000'\n '2012-07-04T09:58:00.000000000' '2012-07-04T12:49:00.000000000'\n '2012-07-04T13:42:00.000000000' '2012-07-05T09:16:00.000000000'\n '2012-07-05T12:08:00.000000000' '2012-07-05T16:12:00.000000000'\n '2012-07-06T13:24:00.000000000' '2012-07-06T18:03:00.000000000'\n '2012-07-07T17:12:00.000000000' '2012-07-08T12:03:00.000000000'\n '2012-07-09T09:20:00.000000000' '2012-07-09T12:15:00.000000000'\n '2012-07-09T14:20:00.000000000' '2012-07-10T09:12:00.000000000'\n '2012-07-10T13:36:00.000000000' '2012-07-11T09:11:00.000000000'\n '2012-07-12T09:21:00.000000000' '2012-07-13T09:19:00.000000000'\n '2012-07-16T12:53:00.000000000' '2012-07-16T16:57:00.000000000'\n '2012-07-17T09:16:00.000000000' '2012-07-20T09:20:00.000000000'\n '2012-07-25T09:16:00.000000000' '2012-07-25T10:39:00.000000000'\n '2012-07-25T10:54:00.000000000' '2012-07-25T14:32:00.000000000'\n '2012-07-26T09:58:00.000000000' '2012-07-26T11:39:00.000000000'\n '2012-07-26T13:38:00.000000000' '2012-07-27T09:16:00.000000000'\n '2012-07-27T11:16:00.000000000' '2012-07-28T20:08:00.000000000'\n '2012-07-30T11:15:00.000000000' '2012-07-30T13:35:00.000000000'\n '2012-07-30T16:10:00.000000000' '2012-07-31T13:26:00.000000000'\n '2012-08-01T13:13:00.000000000' '2012-08-01T14:23:00.000000000'\n '2012-08-02T09:16:00.000000000' '2012-08-02T13:18:00.000000000'\n '2012-08-02T15:46:00.000000000' '2012-08-05T16:35:00.000000000'\n '2012-08-06T11:08:00.000000000' '2012-08-06T11:20:00.000000000'\n '2012-08-06T13:18:00.000000000' '2012-08-06T13:37:00.000000000'\n '2012-08-07T10:38:00.000000000' '2012-08-07T13:02:00.000000000'\n '2012-08-08T09:28:00.000000000' '2012-08-08T12:26:00.000000000'\n '2012-08-08T13:19:00.000000000' '2012-08-08T13:34:00.000000000'\n '2012-08-08T15:49:00.000000000' '2012-08-09T10:44:00.000000000'\n '2012-08-09T11:40:00.000000000' '2012-08-09T13:10:00.000000000'\n '2012-08-09T13:25:00.000000000' '2012-08-09T15:10:00.000000000'\n '2012-08-13T09:36:00.000000000' '2012-08-13T13:46:00.000000000'\n '2012-08-14T09:23:00.000000000' '2012-08-14T10:46:00.000000000'\n '2012-08-14T14:23:00.000000000' '2012-08-14T19:05:00.000000000'\n '2012-08-15T09:27:00.000000000' '2012-08-15T14:16:00.000000000'\n '2012-08-16T09:16:00.000000000' '2012-08-16T15:42:00.000000000'\n '2012-08-17T09:26:00.000000000' '2012-08-17T13:15:00.000000000'\n '2012-08-20T09:28:00.000000000' '2012-08-20T14:10:00.000000000'\n '2012-08-21T10:06:00.000000000' '2012-08-21T13:01:00.000000000'\n '2012-08-21T16:05:00.000000000' '2012-08-22T09:57:00.000000000'\n '2012-08-22T13:52:00.000000000' '2012-08-23T09:17:00.000000000'\n '2012-08-23T13:00:00.000000000' '2012-08-23T13:16:00.000000000'\n '2012-08-24T15:32:00.000000000' '2012-08-25T15:11:00.000000000'\n '2012-08-27T09:55:00.000000000' '2012-08-27T13:53:00.000000000'\n '2012-08-28T10:48:00.000000000' '2012-08-29T13:34:00.000000000'\n '2012-08-30T09:33:00.000000000' '2012-08-30T13:38:00.000000000'\n '2012-08-30T17:36:00.000000000' '2012-08-31T09:24:00.000000000'\n '2012-08-31T11:21:00.000000000' '2012-08-31T13:53:00.000000000'\n '2012-08-31T15:20:00.000000000' '2012-09-01T14:13:00.000000000'\n '2012-09-01T17:43:00.000000000' '2012-09-03T12:19:00.000000000'\n '2012-09-03T16:15:00.000000000' '2012-09-04T11:43:00.000000000'\n '2012-09-04T14:52:00.000000000' '2012-09-05T09:28:00.000000000'\n '2012-09-05T14:06:00.000000000' '2012-09-05T14:48:00.000000000'\n '2012-09-06T13:15:00.000000000' '2012-09-07T09:20:00.000000000'\n '2012-09-07T09:49:00.000000000' '2012-09-07T13:40:00.000000000'\n '2012-09-07T16:53:00.000000000' '2012-09-10T09:30:00.000000000'\n '2012-09-10T13:30:00.000000000' '2012-09-10T17:21:00.000000000'\n '2012-09-11T13:11:00.000000000' '2012-09-12T17:05:00.000000000'\n '2012-09-13T11:07:00.000000000' '2012-09-13T13:15:00.000000000'\n '2012-09-13T14:51:00.000000000' '2012-09-14T07:38:00.000000000'\n '2012-09-14T11:35:00.000000000' '2012-09-15T13:28:00.000000000'\n '2012-09-15T18:53:00.000000000' '2012-09-17T09:37:00.000000000'\n '2012-09-17T13:09:00.000000000' '2012-09-18T10:22:00.000000000'\n '2012-09-19T14:48:00.000000000' '2012-09-20T09:45:00.000000000'\n '2012-09-20T13:04:00.000000000' '2012-09-21T11:51:00.000000000'\n '2012-09-21T12:56:00.000000000' '2012-09-24T13:13:00.000000000'\n '2012-09-24T13:39:00.000000000' '2012-09-24T15:21:00.000000000'\n '2012-09-25T11:10:00.000000000' '2012-09-25T15:38:00.000000000'\n '2012-09-26T09:28:00.000000000' '2012-09-26T12:36:00.000000000'\n '2012-09-26T16:02:00.000000000' '2012-09-27T10:00:00.000000000'\n '2012-09-27T11:50:00.000000000' '2012-09-27T13:32:00.000000000'\n '2012-09-28T09:22:00.000000000' '2012-09-28T10:20:00.000000000'\n '2012-09-28T13:17:00.000000000' '2012-09-29T09:05:00.000000000'\n '2012-09-29T15:16:00.000000000' '2012-10-01T09:23:00.000000000'\n '2012-10-01T09:58:00.000000000' '2012-10-01T12:11:00.000000000'\n '2012-10-01T13:08:00.000000000' '2012-10-03T17:06:00.000000000'\n '2012-10-04T08:20:00.000000000' '2012-10-04T10:40:00.000000000'\n '2012-10-04T12:43:00.000000000' '2012-10-04T14:33:00.000000000'\n '2012-10-05T08:22:00.000000000' '2012-10-05T12:47:00.000000000'\n '2012-10-05T13:02:00.000000000' '2012-10-05T15:10:00.000000000'\n '2012-10-05T17:40:00.000000000' '2012-10-08T13:29:00.000000000'\n '2012-10-08T13:48:00.000000000' '2012-10-08T15:03:00.000000000'\n '2012-10-09T09:44:00.000000000' '2012-10-09T11:16:00.000000000'\n '2012-10-09T12:25:00.000000000' '2012-10-10T10:03:00.000000000'\n '2012-10-10T11:03:00.000000000' '2012-10-10T11:53:00.000000000'\n '2012-10-10T13:10:00.000000000' '2012-10-10T13:45:00.000000000'\n '2012-10-10T15:50:00.000000000' '2012-10-11T10:18:00.000000000'\n '2012-10-11T12:58:00.000000000' '2012-10-12T09:47:00.000000000'\n '2012-10-12T10:50:00.000000000' '2012-10-12T13:34:00.000000000'\n '2012-10-13T12:37:00.000000000' '2012-10-13T15:32:00.000000000'\n '2012-10-14T16:44:00.000000000' '2012-10-15T08:44:00.000000000'\n '2012-10-15T10:35:00.000000000' '2012-10-15T13:24:00.000000000'\n '2012-10-15T14:57:00.000000000' '2012-10-16T12:37:00.000000000'\n '2012-10-17T09:50:00.000000000' '2012-10-17T10:25:00.000000000'\n '2012-10-17T13:00:00.000000000' '2012-10-17T13:01:00.000000000'\n '2012-10-17T13:50:00.000000000' '2012-10-18T09:44:00.000000000'\n '2012-10-18T10:04:00.000000000' '2012-10-18T11:40:00.000000000'\n '2012-10-18T13:41:00.000000000' '2012-10-19T10:20:00.000000000'\n '2012-10-19T16:18:00.000000000' '2012-10-20T14:20:00.000000000'\n '2012-10-20T16:35:00.000000000' '2012-10-20T16:36:00.000000000'\n '2012-10-22T10:46:00.000000000' '2012-10-22T12:08:00.000000000'\n '2012-10-22T13:28:00.000000000' '2012-10-22T16:39:00.000000000'\n '2012-10-23T12:43:00.000000000' '2012-10-25T09:55:00.000000000'\n '2012-10-26T16:03:00.000000000' '2012-10-30T09:36:00.000000000'\n '2012-10-31T12:51:00.000000000' '2012-10-31T14:11:00.000000000'\n '2012-10-31T18:02:00.000000000' '2012-11-01T11:19:00.000000000'\n '2012-11-01T15:20:00.000000000' '2012-11-02T11:38:00.000000000'\n '2012-11-02T13:46:00.000000000' '2012-11-05T11:17:00.000000000'\n '2012-11-05T13:25:00.000000000' '2012-11-06T09:30:00.000000000'\n '2012-11-07T09:53:00.000000000' '2012-11-07T10:59:00.000000000'\n '2012-11-07T12:45:00.000000000' '2012-11-08T11:38:00.000000000'\n '2012-11-08T13:50:00.000000000' '2012-11-09T10:07:00.000000000'\n '2012-11-09T10:26:00.000000000' '2012-11-09T12:11:00.000000000'\n '2012-11-09T12:48:00.000000000' '2012-11-09T13:14:00.000000000'\n '2012-11-12T09:34:00.000000000' '2012-11-12T09:36:00.000000000'\n '2012-11-12T13:21:00.000000000' '2012-11-14T12:50:00.000000000'\n '2012-11-15T14:38:00.000000000' '2012-11-16T10:22:00.000000000'\n '2012-11-16T13:45:00.000000000' '2012-11-19T11:27:00.000000000'\n '2012-11-19T13:18:00.000000000' '2012-11-19T16:27:00.000000000'\n '2012-11-20T10:49:00.000000000' '2012-11-20T12:15:00.000000000'\n '2012-11-20T13:44:00.000000000' '2012-11-21T09:58:00.000000000'\n '2012-11-21T16:27:00.000000000' '2012-11-23T11:38:00.000000000'\n '2012-11-23T12:45:00.000000000' '2012-11-23T13:22:00.000000000'\n '2012-11-23T13:52:00.000000000' '2012-11-24T11:44:00.000000000'\n '2012-11-24T12:49:00.000000000' '2012-11-26T10:00:00.000000000'\n '2012-11-26T10:50:00.000000000' '2012-11-26T13:34:00.000000000'\n '2012-11-28T09:58:00.000000000' '2012-11-28T12:58:00.000000000'\n '2012-11-30T16:07:00.000000000' '2012-12-03T11:21:00.000000000'\n '2012-12-03T17:00:00.000000000' '2012-12-04T10:47:00.000000000'\n '2012-12-04T13:03:00.000000000' '2012-12-04T14:08:00.000000000'\n '2012-12-05T11:13:00.000000000' '2012-12-06T14:36:00.000000000'\n '2012-12-07T11:22:00.000000000' '2012-12-08T12:29:00.000000000'\n '2012-12-08T14:20:00.000000000' '2012-12-08T17:15:00.000000000'\n '2012-12-10T12:12:00.000000000' '2012-12-11T10:29:00.000000000'\n '2012-12-11T14:23:00.000000000' '2012-12-12T09:43:00.000000000'\n '2012-12-12T13:07:00.000000000' '2012-12-12T15:17:00.000000000'\n '2012-12-14T10:24:00.000000000' '2012-12-17T14:36:00.000000000'\n '2012-12-18T11:04:00.000000000' '2012-12-18T13:50:00.000000000'\n '2012-12-21T15:23:00.000000000' '2013-01-08T13:58:00.000000000'\n '2013-01-09T15:25:00.000000000' '2013-01-10T11:05:00.000000000'\n '2013-01-11T10:57:00.000000000' '2013-01-11T13:36:00.000000000'\n '2013-01-11T17:06:00.000000000' '2013-01-15T08:25:00.000000000'\n '2013-01-16T12:38:00.000000000' '2013-01-16T18:09:00.000000000'\n '2013-01-17T13:45:00.000000000' '2013-01-21T14:07:00.000000000'\n '2013-01-28T14:01:00.000000000' '2013-01-29T13:43:00.000000000'\n '2013-01-29T15:06:00.000000000' '2013-02-04T13:25:00.000000000'\n '2013-02-06T17:33:00.000000000' '2013-02-07T13:30:00.000000000'\n '2013-02-12T08:36:00.000000000' '2013-02-12T11:39:00.000000000'\n '2013-02-13T13:58:00.000000000' '2013-02-16T11:55:00.000000000'\n '2013-02-18T13:46:00.000000000' '2013-02-21T13:44:00.000000000'\n '2013-02-21T15:02:00.000000000' '2013-02-25T13:33:00.000000000'\n '2013-02-25T17:25:00.000000000' '2013-02-27T09:33:00.000000000'\n '2013-03-04T10:46:00.000000000' '2013-03-04T11:12:00.000000000'\n '2013-03-04T16:43:00.000000000' '2013-03-05T10:42:00.000000000'\n '2013-03-05T13:29:00.000000000' '2013-03-08T10:28:00.000000000'\n '2013-03-12T08:28:00.000000000' '2013-04-05T11:20:00.000000000'\n '2013-04-27T11:04:00.000000000' '2013-09-12T15:38:00.000000000'\n '2013-09-13T10:28:00.000000000'] not in index"
Plese help
Related
I have a dataframe similar to:
df = pd.DataFrame({'Date': ['2016-01-05', '2016-01-05', '2016-01-05', '2016-01-05', '2016-01-08', '2016-01-08', '2016-02-01'], 'Count': [1, 2, 2, 3, 2, 0, 2]})
and I am trying to plot a histogram of Count for each unique Date
I've tried:
for date in df.Date.unique():
plt.hist([df[df.Date == '%s' %(date)]['Count']])
plt.title('%s' %(date))
which results in
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-17-971a1cf07250> in <module>()
1 for date in df.Date.unique():
----> 2 plt.hist([df[df.Date == '%s' %(date)]['Count']])
3 plt.title('%s' %(date))
c:~\anaconda3\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
2963 histtype=histtype, align=align, orientation=orientation,
2964 rwidth=rwidth, log=log, color=color, label=label,
-> 2965 stacked=stacked, data=data, **kwargs)
2966 finally:
2967 ax.hold(washold)
c:~\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1816 warnings.warn(msg % (label_namer, func.__name__),
1817 RuntimeWarning, stacklevel=2)
-> 1818 return func(ax, *args, **kwargs)
1819 pre_doc = inner.__doc__
1820 if pre_doc is None:
c:~\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
5925
5926 # basic input validation
-> 5927 flat = np.ravel(x)
5928
5929 input_empty = len(flat) == 0
c:~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in ravel(a, order)
1482 return asarray(a).ravel(order=order)
1483 else:
-> 1484 return asanyarray(a).ravel(order=order)
1485
1486
c:~\anaconda3\lib\site-packages\numpy\core\numeric.py in asanyarray(a, dtype, order)
581
582 """
--> 583 return array(a, dtype, copy=False, order=order, subok=True)
584
585
c:~\anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
581 key = com._apply_if_callable(key, self)
582 try:
--> 583 result = self.index.get_value(self, key)
584
585 if not lib.isscalar(result):
c:~\anaconda3\lib\site-packages\pandas\indexes\base.py in get_value(self, series, key)
1978 try:
1979 return self._engine.get_value(s, k,
-> 1980 tz=getattr(series.dtype, 'tz', None))
1981 except KeyError as e1:
1982 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:
pandas\index.pyx in pandas.index.IndexEngine.get_value (pandas\index.c:3332)()
pandas\index.pyx in pandas.index.IndexEngine.get_value (pandas\index.c:3035)()
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4018)()
pandas\hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:6610)()
pandas\hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:6554)()
KeyError: 0
But when I try to simply print it, there is no problem:
for date in df.Date.unique():
print([df[df.Date == '%s' %(date)]['Count']])
[0 1
1 2
2 2
3 3
Name: Count, dtype: int64]
[4 2
5 0
Name: Count, dtype: int64]
[6 2
Name: Count, dtype: int64]
What is the issue with calling plt.hist on my dataframe the way that I have it here?
Essentially you have two square brackets too much in your code.
plt.hist([series]) # <- wrong
plt.hist(series) # <- correct
In the first case matplotlib would try to plot a histogram of a list of one element, which is non-numeric. That won't work.
Instead, removing the brackts and directly supplying the series, works fine
for date in df.Date.unique():
plt.hist(df[df.Date == '%s' %(date)]['Count'])
plt.title('%s' %(date))
Now this will create all histograms in the same plot. Not sure if this is desired. If not, consider the incredibly short alternative:
df.hist(by="Date")
You're passing a list of dataframes, which is causing a problem here. You could deconstruct a groupby object and plot each one separately.
gps = df.groupby('Date').Count
_, axes = plt.subplots(nrows=gps.ngroups)
for (_, g), ax in zip(df.groupby('Date').Count, axes):
g.plot.hist(ax=ax)
plt.show()
Take a look at the Visualisation docs if you need more sugar in your graph.
I get an error when trying to plot inline in a jupyter notebook.
%matplotlib inline
N = 20
M = 10
df = pd.DataFrame(
index=pd.date_range(dtt.date.today(), periods=N),
data=np.random.randn(N, M),
columns=['path_{}'.format(ii) for ii in range(M)]
)
df.plot()
I get the following NonGuiException error. Even though the image plots it seems to raise an exception. If as the index to the dataframe I use range(N) it works just fine which is strange.
Any ideas what is going on?
--------------------------------------------------------------------------- NonGuiException Traceback (most recent call last) in ()
6 columns=['path_{}'.format(ii) for ii in range(M)]
7 )
----> 8 df.plot()
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
__call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds) 3771 fontsize=fontsize, colormap=colormap, table=table, 3772 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3773 sort_columns=sort_columns, **kwds) 3774 __call__.__doc__ = plot_frame.__doc__ 3775
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds) 2640 yerr=yerr, xerr=xerr, 2641 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2642 **kwds) 2643 2644
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
_plot(data, x, y, subplots, ax, kind, **kwds) 2467 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds) 2468
-> 2469 plot_obj.generate() 2470 plot_obj.draw() 2471 return plot_obj.result
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in generate(self) 1041 self._compute_plot_data() 1042 self._setup_subplots()
-> 1043 self._make_plot() 1044 self._add_table() 1045 self._make_legend()
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
_make_plot(self) 1724 stacking_id=stacking_id, 1725 is_errorbar=is_errorbar,
-> 1726 **kwds) 1727 self._add_legend_handle(newlines[0], label, index=i) 1728
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
_ts_plot(cls, ax, x, data, style, **kwds) 1764 lines = cls._plot(ax, data.index, data.values, style=style, **kwds) 1765
# set date formatter, locators and rescale limits
-> 1766 format_dateaxis(ax, ax.freq) 1767 return lines 1768
/usr/local/lib/python3.5/dist-packages/pandas/tseries/plotting.py in format_dateaxis(subplot, freq)
292 "t = {0} y = {1:8f}".format(Period(ordinal=int(t), freq=freq), y))
293
--> 294 pylab.draw_if_interactive()
/usr/local/lib/python3.5/dist-packages/IPython/utils/decorators.py in wrapper(*args, **kw)
41 def wrapper(*args,**kw):
42 wrapper.called = False
---> 43 out = func(*args,**kw)
44 wrapper.called = True
45 return out
/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py in draw_if_interactive()
68 figManager = Gcf.get_active()
69 if figManager is not None:
---> 70 figManager.show()
71
72 class Show(ShowBase):
/usr/lib/python3/dist-packages/matplotlib/backend_bases.py in show(self) 2618 optional warning. 2619 """
-> 2620 raise NonGuiException() 2621 2622 def destroy(self):
NonGuiException:
The command %matplotlib inline sets the backend. Check you haven't set a conflicting backend somewhere else.
I found that I had set my MPLBACKEND environment variable to TkAgg. As soon as I deleted it from my pipenv .env file and restarted my shell and Jupyter notebook server, inline ploting worked again.
I'm trying to plot a pie chart of the titanic survivor data. I have been trying to plot this as a pie chart but I keep getting a KeyError 0. How can I fix this?
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
s_survival = (titanic_data.Survived[titanic_data.Embarked == 'S'][titanic_data.Survived == 1].value_counts()
) / survivors.sum()
c_survival = (titanic_data.Survived[titanic_data.Embarked == 'C'][titanic_data.Survived == 1].value_counts()
) / survivors.sum()
q_survival = (titanic_data.Survived[titanic_data.Embarked == 'Q'][titanic_data.Survived == 1].value_counts()
) / survivors.sum()
labels = ['s_survival', 'c_survival', 'q_survival']
sizes = [s_survival, c_survival, q_survival]
pie(sizes, explode=None, labels=labels, autopct='%1.1f%%', shadow=False, startangle=90)
title('Survivor Percentage from Embarked Port')
Any advice would be greatly appreciated.
StackTrace :
KeyError Traceback (most recent call last)
<ipython-input-18-a8c68ae3422f> in <module>()
11 sizes = [s_survival, c_survival, q_survival]
12 # add a list zip here
---> 13 plt.pie(sizes, explode=None, labels=labels, autopct='%1.1f%%', shadow=False, startangle=90)
14 title('Survivor Percentage from Embarked Port')
//anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in pie(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, hold, data)
3135 radius=radius, counterclock=counterclock,
3136 wedgeprops=wedgeprops, textprops=textprops, center=center,
-> 3137 frame=frame, data=data)
3138 finally:
3139 ax.hold(washold)
//anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1810 warnings.warn(msg % (label_namer, func.__name__),
1811 RuntimeWarning, stacklevel=2)
-> 1812 return func(ax, *args, **kwargs)
1813 pre_doc = inner.__doc__
1814 if pre_doc is None:
//anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in pie(self, x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame)
2546 """
2547
-> 2548 x = np.asarray(x).astype(np.float32)
2549
2550 sx = float(x.sum())
//anaconda/lib/python2.7/site-packages/numpy/core/numeric.pyc in asarray(a, dtype, order)
472
473 """
--> 474 return array(a, dtype, copy=False, order=order)
475
476 def asanyarray(a, dtype=None, order=None):
//anaconda/lib/python2.7/site-packages/pandas/core/series.pyc in __getitem__(self, key)
558 def __getitem__(self, key):
559 try:
--> 560 result = self.index.get_value(self, key)
561
562 if not lib.isscalar(result):
//anaconda/lib/python2.7/site-packages/pandas/indexes/base.pyc in get_value(self, series, key)
1909 try:
1910 return self._engine.get_value(s, k,
-> 1911 tz=getattr(series.dtype, 'tz', None))
1912 except KeyError as e1:
1913 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:
pandas/index.pyx in pandas.index.IndexEngine.get_value (pandas/index.c:3234)()
pandas/index.pyx in pandas.index.IndexEngine.get_value (pandas/index.c:2931)()
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3891)()
pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6527)()
pandas/hashtable.pyx in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6465)()
KeyError: 0
I'm trying to plot using the following code:
df.plot(kind='scatter',x='branch', y='retention', s=df['active_users']*200)
Which gives me the following error:
KeyError Traceback (most recent call last)
<ipython-input-17-e43e5aeff662> in <module>()
3 df = Flexbooks[Flexbooks['schoolyearsemester'] == StartSem][Flexbooks['branch'] != 'OTHE'][Flexbooks['branch'] != 'SSCI'][Flexbooks['branch'] != 'EM1'][Flexbooks['branch'] != 'EM2'][Flexbooks['branch'] != 'EM3'][Flexbooks['branch'] != 'EM4'][Flexbooks['branch'] != 'EM5'][Flexbooks['branch'] != 'SATP'][Flexbooks['branch'] != 'MORE'][Flexbooks['branch'] != 'SPEL'][Flexbooks['branch'] != 'ENG'][Flexbooks['branch'] != 'ENGG'][Flexbooks['branch'] != 'NANO'][Flexbooks['branch'] != 'TECH'][Flexbooks['branch'] != 'HIST'][Flexbooks['branch'] != 'WRIT'][Flexbooks['branch'] != 'ASTR'][Flexbooks['branch'] != 'EXAP']
4
----> 5 df.plot(kind='scatter',x='branch', y='retention', s=df['active_users']*200)
6 #df.plot.scatter(x='branch', y='retention', s=df['active_users']*200)
E:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
E:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
E:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
E:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in generate(self)
985 self._compute_plot_data()
986 self._setup_subplots()
--> 987 self._make_plot()
988 self._add_table()
989 self._make_legend()
E:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _make_plot(self)
1556 else:
1557 label = None
-> 1558 scatter = ax.scatter(data[x].values, data[y].values, c=c_values,
1559 label=label, cmap=cmap, **self.kwds)
1560 if cb:
E:\Anaconda2\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key)
1967 return self._getitem_multilevel(key)
1968 else:
-> 1969 return self._getitem_column(key)
1970
1971 def _getitem_column(self, key):
E:\Anaconda2\lib\site-packages\pandas\core\frame.pyc in _getitem_column(self, key)
1974 # get column
1975 if self.columns.is_unique:
-> 1976 return self._get_item_cache(key)
1977
1978 # duplicate columns & possible reduce dimensionality
E:\Anaconda2\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item)
1089 res = cache.get(item)
1090 if res is None:
-> 1091 values = self._data.get(item)
1092 res = self._box_item_values(item, values)
1093 cache[item] = res
E:\Anaconda2\lib\site-packages\pandas\core\internals.pyc in get(self, item, fastpath)
3209
3210 if not isnull(item):
-> 3211 loc = self.items.get_loc(item)
3212 else:
3213 indexer = np.arange(len(self.items))[isnull(self.items)]
E:\Anaconda2\lib\site-packages\pandas\core\index.pyc in get_loc(self, key, method, tolerance)
1757 'backfill or nearest lookups')
1758 key = _values_from_object(key)
-> 1759 return self._engine.get_loc(key)
1760
1761 indexer = self.get_indexer([key], method=method,
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:3979)()
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:3843)()
pandas\hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12265)()
pandas\hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12216)()
KeyError: 'branch'
I can confidently say that the column 'branch' exists, then why the KeyError?
I know this problem exists when the column in datetime, but this column is string.
Any help would be appreciated.
I have encountered an error while working through Ch12 of the book Numerical Python: A Practical Techniques Approach for Industry (http://jrjohansson.github.io/numericalpython.html).
I am getting an error when I try to plot a series object using the pandas library.
So far the following lines of code have worked:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
pd.set_option('display.mpl_style', 'default')
s = pd.Series([909976, 8615246, 2872086, 2273305])
s
0 909976
1 8615246
2 2872086
3 2273305
dtype: int64
When I plot the series object s I get the following error:
AttributeError Traceback (most recent call last)
<ipython-input-81-d3eb09d34df4> in <module>()
----> 1 s.plot()
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in generate(self)
985 self._compute_plot_data()
986 self._setup_subplots()
--> 987 self._make_plot()
988 self._add_table()
989 self._make_legend()
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _make_plot(self)
1662 stacking_id=stacking_id,
1663 is_errorbar=is_errorbar,
-> 1664 **kwds)
1665 self._add_legend_handle(newlines[0], label, index=i)
1666
anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, column_num, stacking_id, **kwds)
1676 cls._initialize_stacker(ax, stacking_id, len(y))
1677 y_values = cls._get_stacked_values(ax, stacking_id, y, kwds['label'])
-> 1678 lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds)
1679 cls._update_stacker(ax, stacking_id, y)
1680 return lines
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, is_errorbar, **kwds)
1298 else:
1299 args = (x, y)
-> 1300 return ax.plot(*args, **kwds)
1301
1302 def _get_index_name(self):
/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1809 warnings.warn(msg % (label_namer, func.__name__),
1810 RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
1812 pre_doc = inner.__doc__
1813 if pre_doc is None:
/anaconda/lib/python3.5/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1425 kwargs['color'] = c
1426
-> 1427 for line in self._get_lines(*args, **kwargs):
1428 self.add_line(line)
1429 lines.append(line)
/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
384 return
385 if len(remaining) <= 3:
--> 386 for seg in self._plot_args(remaining, kwargs):
387 yield seg
388 return
anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
372 ncx, ncy = x.shape[1], y.shape[1]
373 for j in xrange(max(ncx, ncy)):
--> 374 seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
375 ret.append(seg)
376 return ret
/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in _makeline(self, x, y, kw, kwargs)
278 default_dict = self._getdefaults(None, kw, kwargs)
279 self._setdefaults(default_dict, kw, kwargs)
--> 280 seg = mlines.Line2D(x, y, **kw)
281 self.set_lineprops(seg, **kwargs)
282 return seg
/anaconda/lib/python3.5/site-packages/matplotlib/lines.py in __init__(self, xdata, ydata, linewidth, linestyle, color, marker, markersize, markeredgewidth, markeredgecolor, markerfacecolor, markerfacecoloralt, fillstyle, antialiased, dash_capstyle, solid_capstyle, dash_joinstyle, solid_joinstyle, pickradius, drawstyle, markevery, **kwargs)
364 # update kwargs before updating data to give the caller a
365 # chance to init axes (and hence unit support)
--> 366 self.update(kwargs)
367 self.pickradius = pickradius
368 self.ind_offset = 0
/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in update(self, props)
854 func = getattr(self, 'set_' + k, None)
855 if func is None or not six.callable(func):
--> 856 raise AttributeError('Unknown property %s' % k)
857 func(v)
858 changed = True
AttributeError: Unknown property color_cycle
I have a 64 bit linux OS and the most recent anaconda installed.