Sinchetru
Sinchetru

Reputation: 571

Ho to fix ValueError: too many values to unpack (expected 3)?

I have this piece of code and it gives me the desired result but also show me an error, what does this error mean and how to fix it?

s_and = df_android['Category']
total_and = s_and.value_counts()
percentage_and = s_and.value_counts(normalize=True).mul(100).round(2)

percentage_tab_and = pd.DataFrame({'Total':total_and, 'Percentage':percentage_and}).reset_index()
percentage_tab_and = percentage_tab_and.rename(columns={"index": "Category"})
percentage_tab_and.head(5)

Result:

|  Category   | Total       | Percentage |
| ----------- | ----------- |------------|
| Dict        | 3           |    36      |
| Book        | 2           |    24      |

Error:

ValueError                                Traceback (most recent call last)
~\anaconda3\lib\site-packages\pycodestyle_magic.py in auto_run_pycodestyle(self, result)
     44 
     45     def auto_run_pycodestyle(self, result):
---> 46         pycodestyle(1, result.info.raw_cell, auto=True)
     47         if result.error_before_exec:
     48             print('Error before execution: %s' % result.error_before_exec)

<C:\Users\Sinch\anaconda3\lib\site-packages\decorator.py:decorator-gen-131> in pycodestyle(line, cell, auto)

~\anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    218     # but it's overkill for just that one bit of state.
    219     def magic_deco(arg):
--> 220         call = lambda f, *a, **k: f(*a, **k)
    221 
    222         # Find get_ipython() in the caller's namespace

~\anaconda3\lib\site-packages\pycodestyle_magic.py in pycodestyle(line, cell, auto)
    173         #logger.info(line)
    174         # on windows drive path also contains :
--> 175         line, col, error = line.split(':')[-4:]
    176         # do not subtract 1 for line for %%pycodestyle, inc pre py3.6 string
    177         if auto:

ValueError: too many values to unpack (expected 3)

Upvotes: 2

Views: 1760

Answers (2)

unDeadHerbs
unDeadHerbs

Reputation: 1403

There is now a PR that fixes that bug. It's easy to copy the change into your local version until it's accepted.

https://github.com/mattijn/pycodestyle_magic/pull/32

Upvotes: 0

Andrew Ward
Andrew Ward

Reputation: 11

It looks like this is an open issue with pycodestyle_magic regarding colons: https://github.com/mattijn/pycodestyle_magic/issues/20

As a workaround until the issue is fixed, you could disable the pycodestyle_magic for the lines with colons:

%pycodestyle_off
percentage_tab_and = pd.DataFrame({'Total':total_and, 'Percentage':percentage_and}).reset_index()
percentage_tab_and = percentage_tab_and.rename(columns={"index": "Category"})
%pycodestyle_on

Upvotes: 1

Related Questions