Created
November 26, 2018 17:43
-
-
Save alpenmilch411/fb0f7c4e9095eb8e5e31a1d764aba0f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code: | |
# Distribution table - Outlook | |
sp_outlook_distr.pivot_table(index=["Type"], columns=sp_outlook_distr["Date"].dt.year, aggfunc={"Date": np.count_nonzero}, fill_value=0, margins=True) | |
Error: | |
--------------------------------------------------------------------------- | |
KeyError Traceback (most recent call last) | |
<ipython-input-87-fdd674d20a28> in <module>() | |
1 # Distribution table - Outlook | |
----> 2 sp_outlook_distr.pivot_table(index=["Type"], columns=sp_outlook_distr["Date"].dt.year, aggfunc={"Date": np.count_nonzero}, fill_value=0, margins=True) | |
~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in pivot_table(self, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name) | |
5298 aggfunc=aggfunc, fill_value=fill_value, | |
5299 margins=margins, dropna=dropna, | |
-> 5300 margins_name=margins_name) | |
5301 | |
5302 def stack(self, level=-1, dropna=True): | |
~/anaconda3/lib/python3.6/site-packages/pandas/core/reshape/pivot.py in pivot_table(data, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name) | |
122 cols=columns, aggfunc=aggfunc, | |
123 observed=dropna, | |
--> 124 margins_name=margins_name, fill_value=fill_value) | |
125 | |
126 # discard the top level | |
~/anaconda3/lib/python3.6/site-packages/pandas/core/reshape/pivot.py in _add_margins(table, data, values, rows, cols, aggfunc, observed, margins_name, fill_value) | |
149 raise ValueError(msg) | |
150 | |
--> 151 grand_margin = _compute_grand_margin(data, values, aggfunc, margins_name) | |
152 | |
153 # could be passed a Series object with no 'columns' | |
~/anaconda3/lib/python3.6/site-packages/pandas/core/reshape/pivot.py in _compute_grand_margin(data, values, aggfunc, margins_name) | |
219 grand_margin[k] = getattr(v, aggfunc)() | |
220 elif isinstance(aggfunc, dict): | |
--> 221 if isinstance(aggfunc[k], compat.string_types): | |
222 grand_margin[k] = getattr(v, aggfunc[k])() | |
223 else: | |
KeyError: 'Sovereign' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment