python - 初学者 - Python .sort() 中的 TypeError
问题描述
我将通过从 Python 中的 Excel 文件中读取数据来对数据进行排序。
但是,我遇到了一些错误,下面是我的代码。
mp_list = []
for i in range(2, maxRow_input+1):
mp=sheet_input.cell(i,mp_index).value
mp_list.append(mp)
mp_list.sort()
print(mp_list)
这就是我收到的错误消息:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-110-9af441d1bedd> in <module>
3 mp=sheet_input.cell(i,mp_index).value
4 mp_list.append(mp)
----> 5 mp_list.sort()
6 print(mp_list)
TypeError: '<' not supported between instances of 'str' and 'int'
谁能帮我解决这个问题,请给我解释一下:)
解决方案
请检查该 excel 列中的值是否具有相同的数据类型。似乎该列具有不同的数据类型,因此排序给出了错误。
推荐阅读
- java - 类型 类型不能是 Do 的超接口;超接口必须是接口错误
- node.js - 猫鼬模式类型和参考?它们是 .populate 方法的关键词吗?还是它们是任意词?
- python - python boto3分段上传到不同区域的桶
- swift - Swift segues 是紧密耦合的吗?
- angular - 类型'可观察的
' 不可分配给类型 'Observable ' - python - 我无法使用 Matplotlib 以 pdf 格式保存绘图
- swift - Swift - ArrayController,它什么时候充满数据?
- algorithm - O(n log n) 算法总是优于所有 O(n^2) 算法吗?
- python - UTF-8 编码阻塞控制台打印
- android - 在科尔多瓦禁用 CORS 保护