pandas: subplotting scatter plots on df.pivot() causes KeyError












1















I created a dataframe from df.pivot() that looks like this:



cluster    0     1    2    3     4    5     6      7    8     9
value
5 0 0 1 1 2 1 1 3 0 0
20 0 0 0 0 0 0 0 1 0 0
22 0 0 0 0 0 0 1 0 0 0
50 0 0 0 0 0 0 0 1 0 0
100 211 493 133 180 262 19 782 6295 137 517
200 667 1685 444 588 877 242 2630 21077 494 1751
250 0 1 0 0 0 0 0 3 1 0
300 180 480 133 177 234 20 744 5985 236 474
350 0 0 0 0 0 0 0 1 1 0


I am trying to create a grid of multiple scatter plots, one scatter plot for each cluster. Something that can resemble this:



Sample scatter subplot



This is what I have been trying:



chart = df.plot(
kind = 'scatter',
x = 'value',
y = 'cluster',
subplots = True,
sharex = True,
title = "Question value distribution across clusters"
)


This is resulting in a KeyError indicating that the plot is unable to access the pivot table columns. Here's the log:



KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2524 try:
-> 2525 return self._engine.get_loc(key)
2526 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
<ipython-input-90-175952b92cec> in <module>()
10 rk = gk.pivot(index = 'value', columns = 'cluster', values = 'count').fillna(0)
11 rk = rk.astype('int')
---> 12 chart = xk.plot(kind = 'scatter', x = 'value', y = 'cluster', subplots = True, sharex = True, title = "Question value distribution for cluster "+str(cluster_no))
13 # chart.set_xlabel("Value of question ($)")
14 # chart.set_ylabel("Questions in cluster")

/usr/local/lib/python3.6/dist-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)
2675 fontsize=fontsize, colormap=colormap, table=table,
2676 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2677 sort_columns=sort_columns, **kwds)
2678 __call__.__doc__ = plot_frame.__doc__
2679

/usr/local/lib/python3.6/dist-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)
1900 yerr=yerr, xerr=xerr,
1901 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1902 **kwds)
1903
1904

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1685 if isinstance(data, DataFrame):
1686 plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-> 1687 kind=kind, **kwds)
1688 else:
1689 raise ValueError("plot kind %r can only be used for data frames"

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
835 # the handling of this argument later
836 s = 20
--> 837 super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
838 if is_integer(c) and not self.data.columns.holds_integer():
839 c = self.data.columns[c]

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
811 if len(self.data[x]._get_numeric_data()) == 0:
812 raise ValueError(self._kind + ' requires x column to be numeric')
--> 813 if len(self.data[y]._get_numeric_data()) == 0:
814 raise ValueError(self._kind + ' requires y column to be numeric')
815

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __getitem__(self, key)
2137 return self._getitem_multilevel(key)
2138 else:
-> 2139 return self._getitem_column(key)
2140
2141 def _getitem_column(self, key):

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _getitem_column(self, key)
2144 # get column
2145 if self.columns.is_unique:
-> 2146 return self._get_item_cache(key)
2147
2148 # duplicate columns & possible reduce dimensionality

/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in _get_item_cache(self, item)
1840 res = cache.get(item)
1841 if res is None:
-> 1842 values = self._data.get(item)
1843 res = self._box_item_values(item, values)
1844 cache[item] = res

/usr/local/lib/python3.6/dist-packages/pandas/core/internals.py in get(self, item, fastpath)
3841
3842 if not isna(item):
-> 3843 loc = self.items.get_loc(item)
3844 else:
3845 indexer = np.arange(len(self.items))[isna(self.items)]

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2525 return self._engine.get_loc(key)
2526 except KeyError:
-> 2527 return self._engine.get_loc(self._maybe_cast_indexer(key))
2528
2529 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'


How do I get through this?










share|improve this question

























  • Your results will vary depending on how your dataframe is constructed. Please provide a sample input that allows users to recreate your problem.

    – Mr. T
    Nov 25 '18 at 11:33


















1















I created a dataframe from df.pivot() that looks like this:



cluster    0     1    2    3     4    5     6      7    8     9
value
5 0 0 1 1 2 1 1 3 0 0
20 0 0 0 0 0 0 0 1 0 0
22 0 0 0 0 0 0 1 0 0 0
50 0 0 0 0 0 0 0 1 0 0
100 211 493 133 180 262 19 782 6295 137 517
200 667 1685 444 588 877 242 2630 21077 494 1751
250 0 1 0 0 0 0 0 3 1 0
300 180 480 133 177 234 20 744 5985 236 474
350 0 0 0 0 0 0 0 1 1 0


I am trying to create a grid of multiple scatter plots, one scatter plot for each cluster. Something that can resemble this:



Sample scatter subplot



This is what I have been trying:



chart = df.plot(
kind = 'scatter',
x = 'value',
y = 'cluster',
subplots = True,
sharex = True,
title = "Question value distribution across clusters"
)


This is resulting in a KeyError indicating that the plot is unable to access the pivot table columns. Here's the log:



KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2524 try:
-> 2525 return self._engine.get_loc(key)
2526 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
<ipython-input-90-175952b92cec> in <module>()
10 rk = gk.pivot(index = 'value', columns = 'cluster', values = 'count').fillna(0)
11 rk = rk.astype('int')
---> 12 chart = xk.plot(kind = 'scatter', x = 'value', y = 'cluster', subplots = True, sharex = True, title = "Question value distribution for cluster "+str(cluster_no))
13 # chart.set_xlabel("Value of question ($)")
14 # chart.set_ylabel("Questions in cluster")

/usr/local/lib/python3.6/dist-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)
2675 fontsize=fontsize, colormap=colormap, table=table,
2676 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2677 sort_columns=sort_columns, **kwds)
2678 __call__.__doc__ = plot_frame.__doc__
2679

/usr/local/lib/python3.6/dist-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)
1900 yerr=yerr, xerr=xerr,
1901 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1902 **kwds)
1903
1904

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1685 if isinstance(data, DataFrame):
1686 plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-> 1687 kind=kind, **kwds)
1688 else:
1689 raise ValueError("plot kind %r can only be used for data frames"

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
835 # the handling of this argument later
836 s = 20
--> 837 super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
838 if is_integer(c) and not self.data.columns.holds_integer():
839 c = self.data.columns[c]

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
811 if len(self.data[x]._get_numeric_data()) == 0:
812 raise ValueError(self._kind + ' requires x column to be numeric')
--> 813 if len(self.data[y]._get_numeric_data()) == 0:
814 raise ValueError(self._kind + ' requires y column to be numeric')
815

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __getitem__(self, key)
2137 return self._getitem_multilevel(key)
2138 else:
-> 2139 return self._getitem_column(key)
2140
2141 def _getitem_column(self, key):

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _getitem_column(self, key)
2144 # get column
2145 if self.columns.is_unique:
-> 2146 return self._get_item_cache(key)
2147
2148 # duplicate columns & possible reduce dimensionality

/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in _get_item_cache(self, item)
1840 res = cache.get(item)
1841 if res is None:
-> 1842 values = self._data.get(item)
1843 res = self._box_item_values(item, values)
1844 cache[item] = res

/usr/local/lib/python3.6/dist-packages/pandas/core/internals.py in get(self, item, fastpath)
3841
3842 if not isna(item):
-> 3843 loc = self.items.get_loc(item)
3844 else:
3845 indexer = np.arange(len(self.items))[isna(self.items)]

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2525 return self._engine.get_loc(key)
2526 except KeyError:
-> 2527 return self._engine.get_loc(self._maybe_cast_indexer(key))
2528
2529 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'


How do I get through this?










share|improve this question

























  • Your results will vary depending on how your dataframe is constructed. Please provide a sample input that allows users to recreate your problem.

    – Mr. T
    Nov 25 '18 at 11:33
















1












1








1








I created a dataframe from df.pivot() that looks like this:



cluster    0     1    2    3     4    5     6      7    8     9
value
5 0 0 1 1 2 1 1 3 0 0
20 0 0 0 0 0 0 0 1 0 0
22 0 0 0 0 0 0 1 0 0 0
50 0 0 0 0 0 0 0 1 0 0
100 211 493 133 180 262 19 782 6295 137 517
200 667 1685 444 588 877 242 2630 21077 494 1751
250 0 1 0 0 0 0 0 3 1 0
300 180 480 133 177 234 20 744 5985 236 474
350 0 0 0 0 0 0 0 1 1 0


I am trying to create a grid of multiple scatter plots, one scatter plot for each cluster. Something that can resemble this:



Sample scatter subplot



This is what I have been trying:



chart = df.plot(
kind = 'scatter',
x = 'value',
y = 'cluster',
subplots = True,
sharex = True,
title = "Question value distribution across clusters"
)


This is resulting in a KeyError indicating that the plot is unable to access the pivot table columns. Here's the log:



KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2524 try:
-> 2525 return self._engine.get_loc(key)
2526 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
<ipython-input-90-175952b92cec> in <module>()
10 rk = gk.pivot(index = 'value', columns = 'cluster', values = 'count').fillna(0)
11 rk = rk.astype('int')
---> 12 chart = xk.plot(kind = 'scatter', x = 'value', y = 'cluster', subplots = True, sharex = True, title = "Question value distribution for cluster "+str(cluster_no))
13 # chart.set_xlabel("Value of question ($)")
14 # chart.set_ylabel("Questions in cluster")

/usr/local/lib/python3.6/dist-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)
2675 fontsize=fontsize, colormap=colormap, table=table,
2676 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2677 sort_columns=sort_columns, **kwds)
2678 __call__.__doc__ = plot_frame.__doc__
2679

/usr/local/lib/python3.6/dist-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)
1900 yerr=yerr, xerr=xerr,
1901 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1902 **kwds)
1903
1904

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1685 if isinstance(data, DataFrame):
1686 plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-> 1687 kind=kind, **kwds)
1688 else:
1689 raise ValueError("plot kind %r can only be used for data frames"

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
835 # the handling of this argument later
836 s = 20
--> 837 super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
838 if is_integer(c) and not self.data.columns.holds_integer():
839 c = self.data.columns[c]

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
811 if len(self.data[x]._get_numeric_data()) == 0:
812 raise ValueError(self._kind + ' requires x column to be numeric')
--> 813 if len(self.data[y]._get_numeric_data()) == 0:
814 raise ValueError(self._kind + ' requires y column to be numeric')
815

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __getitem__(self, key)
2137 return self._getitem_multilevel(key)
2138 else:
-> 2139 return self._getitem_column(key)
2140
2141 def _getitem_column(self, key):

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _getitem_column(self, key)
2144 # get column
2145 if self.columns.is_unique:
-> 2146 return self._get_item_cache(key)
2147
2148 # duplicate columns & possible reduce dimensionality

/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in _get_item_cache(self, item)
1840 res = cache.get(item)
1841 if res is None:
-> 1842 values = self._data.get(item)
1843 res = self._box_item_values(item, values)
1844 cache[item] = res

/usr/local/lib/python3.6/dist-packages/pandas/core/internals.py in get(self, item, fastpath)
3841
3842 if not isna(item):
-> 3843 loc = self.items.get_loc(item)
3844 else:
3845 indexer = np.arange(len(self.items))[isna(self.items)]

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2525 return self._engine.get_loc(key)
2526 except KeyError:
-> 2527 return self._engine.get_loc(self._maybe_cast_indexer(key))
2528
2529 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'


How do I get through this?










share|improve this question
















I created a dataframe from df.pivot() that looks like this:



cluster    0     1    2    3     4    5     6      7    8     9
value
5 0 0 1 1 2 1 1 3 0 0
20 0 0 0 0 0 0 0 1 0 0
22 0 0 0 0 0 0 1 0 0 0
50 0 0 0 0 0 0 0 1 0 0
100 211 493 133 180 262 19 782 6295 137 517
200 667 1685 444 588 877 242 2630 21077 494 1751
250 0 1 0 0 0 0 0 3 1 0
300 180 480 133 177 234 20 744 5985 236 474
350 0 0 0 0 0 0 0 1 1 0


I am trying to create a grid of multiple scatter plots, one scatter plot for each cluster. Something that can resemble this:



Sample scatter subplot



This is what I have been trying:



chart = df.plot(
kind = 'scatter',
x = 'value',
y = 'cluster',
subplots = True,
sharex = True,
title = "Question value distribution across clusters"
)


This is resulting in a KeyError indicating that the plot is unable to access the pivot table columns. Here's the log:



KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2524 try:
-> 2525 return self._engine.get_loc(key)
2526 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
<ipython-input-90-175952b92cec> in <module>()
10 rk = gk.pivot(index = 'value', columns = 'cluster', values = 'count').fillna(0)
11 rk = rk.astype('int')
---> 12 chart = xk.plot(kind = 'scatter', x = 'value', y = 'cluster', subplots = True, sharex = True, title = "Question value distribution for cluster "+str(cluster_no))
13 # chart.set_xlabel("Value of question ($)")
14 # chart.set_ylabel("Questions in cluster")

/usr/local/lib/python3.6/dist-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)
2675 fontsize=fontsize, colormap=colormap, table=table,
2676 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2677 sort_columns=sort_columns, **kwds)
2678 __call__.__doc__ = plot_frame.__doc__
2679

/usr/local/lib/python3.6/dist-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)
1900 yerr=yerr, xerr=xerr,
1901 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1902 **kwds)
1903
1904

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1685 if isinstance(data, DataFrame):
1686 plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax,
-> 1687 kind=kind, **kwds)
1688 else:
1689 raise ValueError("plot kind %r can only be used for data frames"

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, s, c, **kwargs)
835 # the handling of this argument later
836 s = 20
--> 837 super(ScatterPlot, self).__init__(data, x, y, s=s, **kwargs)
838 if is_integer(c) and not self.data.columns.holds_integer():
839 c = self.data.columns[c]

/usr/local/lib/python3.6/dist-packages/pandas/plotting/_core.py in __init__(self, data, x, y, **kwargs)
811 if len(self.data[x]._get_numeric_data()) == 0:
812 raise ValueError(self._kind + ' requires x column to be numeric')
--> 813 if len(self.data[y]._get_numeric_data()) == 0:
814 raise ValueError(self._kind + ' requires y column to be numeric')
815

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __getitem__(self, key)
2137 return self._getitem_multilevel(key)
2138 else:
-> 2139 return self._getitem_column(key)
2140
2141 def _getitem_column(self, key):

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _getitem_column(self, key)
2144 # get column
2145 if self.columns.is_unique:
-> 2146 return self._get_item_cache(key)
2147
2148 # duplicate columns & possible reduce dimensionality

/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in _get_item_cache(self, item)
1840 res = cache.get(item)
1841 if res is None:
-> 1842 values = self._data.get(item)
1843 res = self._box_item_values(item, values)
1844 cache[item] = res

/usr/local/lib/python3.6/dist-packages/pandas/core/internals.py in get(self, item, fastpath)
3841
3842 if not isna(item):
-> 3843 loc = self.items.get_loc(item)
3844 else:
3845 indexer = np.arange(len(self.items))[isna(self.items)]

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2525 return self._engine.get_loc(key)
2526 except KeyError:
-> 2527 return self._engine.get_loc(self._maybe_cast_indexer(key))
2528
2529 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'cluster'


How do I get through this?







python pandas matplotlib subplot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 9:55







Mayukh Nair

















asked Nov 25 '18 at 9:49









Mayukh NairMayukh Nair

2581318




2581318













  • Your results will vary depending on how your dataframe is constructed. Please provide a sample input that allows users to recreate your problem.

    – Mr. T
    Nov 25 '18 at 11:33





















  • Your results will vary depending on how your dataframe is constructed. Please provide a sample input that allows users to recreate your problem.

    – Mr. T
    Nov 25 '18 at 11:33



















Your results will vary depending on how your dataframe is constructed. Please provide a sample input that allows users to recreate your problem.

– Mr. T
Nov 25 '18 at 11:33







Your results will vary depending on how your dataframe is constructed. Please provide a sample input that allows users to recreate your problem.

– Mr. T
Nov 25 '18 at 11:33














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466337%2fpandas-subplotting-scatter-plots-on-df-pivot-causes-keyerror%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466337%2fpandas-subplotting-scatter-plots-on-df-pivot-causes-keyerror%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland