小编cro*_*bot的帖子

Python groupby错误,'unhashable'系列对象

我有一个Pandas DataFrame值(浮点数)和国家名称字符串("UNITED STATES","UNITED KINGDOM"等).我想根据国家总结价值观:

Data['Values'].groupby(Data['Country']).sum()
Run Code Online (Sandbox Code Playgroud)

不幸的是,我收到以下错误:

TypeError: 'Series' objects are mutable, thus they cannot be hashed
Run Code Online (Sandbox Code Playgroud)

此外,如果我尝试将由国家/地区组成的系列独一无二:

Data['Country'].unique()
Run Code Online (Sandbox Code Playgroud)

我犯了同样的错误:

TypeError: 'Series' objects are mutable, thus they cannot be hashed
Run Code Online (Sandbox Code Playgroud)

为什么会出现此错误?这是国名吗?任何帮助将不胜感激.我使用的是Python 3.4和Pandas 0.15.2.

python python-3.x pandas

3
推荐指数
1
解决办法
6398
查看次数

Python-docx 样式格式

我正在使用 python-docx 将 Pandas DataFrame 输出到 Word 表。大约一年前,我编写了这段代码来构建那个当时有效的表:

table = Rpt.add_table(rows=1, cols=(df.shape[1]+1))
table.style = 'LightShading-Accent2'
Run Code Online (Sandbox Code Playgroud)

Rpt模板中的文档在哪里。现在,我收到一个错误:

KeyError: "no style with name 'LightShading-Accent2'"
Run Code Online (Sandbox Code Playgroud)

我应该如何定义风格?较新版本的 python-docx 中的命名约定是否发生了变化?

python pandas python-docx

2
推荐指数
1
解决办法
1573
查看次数

标签 统计

pandas ×2

python ×2

python-3.x ×1

python-docx ×1