首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复ValueError:要解压的值太多(预期为3)?

如何修复ValueError:要解压的值太多(预期为3)?
EN

Stack Overflow用户
提问于 2020-04-15 21:29:32
回答 1查看 618关注 0票数 2

我有这段代码,它给了我想要的结果,但也显示了一个错误,这个错误意味着什么,以及如何修复它?

代码语言:javascript
复制
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)

结果:

代码语言:javascript
复制
|  Category   | Total       | Percentage |
| ----------- | ----------- |------------|
| Dict        | 3           |    36      |
| Book        | 2           |    24      |

错误:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2020-10-28 04:09:33

看起来这是一个关于冒号的pycodestyle_magic问题:https://github.com/mattijn/pycodestyle_magic/issues/20

作为解决此问题的一种方法,您可以禁用带有冒号的行的pycodestyle_magic

代码语言:javascript
复制
%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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61230004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档