E:\anaconda\python.exe C:/Users/lenovo/PycharmProjects/pythonProject4/17.py {'光明': 41, '南山': 127, '宝安': 59, '布吉': 57, '盐田': 66, '福田': 109, '罗湖': 85, '龙华': 61, '龙岗': 51} Traceback (most recent call last): File "C:\Users\lenovo\PycharmProjects\pythonProject4\17.py", line 18, in <module> squarify.plot(sizes=sizes,label=label, edgecolor='white', linewidth=3) File "E:\anaconda\lib\site-packages\squarify\__init__.py", line 241, in plot normed = normalize_sizes(sizes, norm_x, norm_y) File "E:\anaconda\lib\site-packages\squarify\__init__.py", line 170, in normalize_sizes total_size = sum(sizes) TypeError: unsupported operand type(s) for +: 'int' and 'str'
时间: 2024-04-08 10:30:56 浏览: 245
根据错误信息,问题出在对数据进行求和的地方。具体来说,`TypeError: unsupported operand type(s) for +: 'int' and 'str'` 表示无法将整数和字符串相加。
根据你提供的代码,可能的原因是 `sizes` 字典中的值是字符串类型,而 `squarify.plot()` 函数要求值为数值类型。请确保 `sizes` 字典中的值为数值类型。
你可以尝试将 `sizes` 字典的值转换为整数类型,例如:
```python
sizes = {key: int(value) for key, value in sizes.items()}
```
在这之后,再运行代码看看是否还会出现同样的错误。如果问题仍然存在,请检查一下 `data` 数据框中的 `unit_price` 列是否包含了非数值类型的数据。
相关问题
C:\Users\86135\anaconda3\envs\pythonProject4\python.exe C:/Users/86135/PycharmProjects/pythonProject4/7.19.1.py File "C:/Users/86135/PycharmProjects/pythonProject4/7.19.1.py", line 7 SyntaxError: Non-UTF-8 code starting with '\xb1' in file C:/Users/86135/PycharmProjects/pythonProject4/7.19.1.py on line 7, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 进程已结束,退出代码为 1
这个错误是由于你的Python代码文件中包含非UTF-8编码的字符导致的。Python默认使用UTF-8编码来解析源代码文件,因此如果你的文件中包含其他编码的字符,就需要在文件开头声明编码方式。
你可以在代码文件开头添加以下注释来声明文件的编码方式:
```
# -*- coding: utf-8 -*-
```
这样Python解释器就会按照UTF-8编码来解析文件中的内容。请确保你的代码文件中的所有字符都能够被UTF-8编码正确表示,如果有特殊字符或其他编码方式的字符,可能会导致解析错误。
同时,也可以使用支持你代码文件编码方式的编辑器来打开和保存代码文件,以确保文件的编码方式与代码内容一致。
(base) C:\Users\Siris>conda create -n mylab python3.10 Collecting package metadata (current_repodata.json): done Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source. Collecting package metadata (repodata.json): done Solving environment: failed PackagesNotFoundError: The following packages are not available from current channels: - python3.10 Current channels: - https://repo.anaconda.com/pkgs/main/win-64 - https://repo.anaconda.com/pkgs/main/noarch - https://repo.anaconda.com/pkgs/r/win-64 - https://repo.anaconda.com/pkgs/r/noarch - https://repo.anaconda.com/pkgs/msys2/win-64 - https://repo.anaconda.com/pkgs/msys2/noarch To search for alternate channels that may provide the conda package you're looking for, navigate to https://anaconda.org and use the search bar at the top of the page.
看起来你是在使用conda创建一个名为"mylab"的环境,并且想要使用Python3.10。然而,当前的conda渠道中似乎没有Python3.10这个版本的包。你可以尝试去https://anaconda.org搜索是否有其他可用的渠道提供Python3.10包,或者选择其他Python版本来创建你的环境。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044736.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)