File "/usr/local/lib/python3.10/site-packages/pandas/core/nanops.py", line 1637, in func return np.corrcoef(a, b)[0, 1] File "<__array_function__ internals>", line 180, in corrcoef File "/usr/local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2845, in corrcoef c = cov(x, y, rowvar, dtype=dtype) File "<__array_function__ internals>", line 180, in cov File "/usr/local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2680, in cov avg, w_sum = average(X, axis=1, weights=w, returned=True) File "<__array_function__ internals>", line 180, in average File "/usr/local/lib/python3.10/site-packages/numpy/lib/function_base.py", line 518, in average avg = a.mean(axis, **keepdims_kw) File "/usr/local/lib/python3.10/site-packages/numpy/core/_methods.py", line 182, in _mean ret = um.true_divide( TypeError: unsupported operand type(s) for /: 'str' and 'int'
时间: 2023-12-15 10:03:16 浏览: 155
这个错误信息提示出现了类型错误,即在计算相关系数时出现了字符串和整数相除的情况。这很可能是因为相关系数计算的两列数据中存在字符串类型的数据,而相关系数只支持数值类型的数据计算。解决这个问题的方法是,在读取 Excel 文件时,需要将相关列的数据类型转换为数值类型,例如使用 `df.astype(float)` 将 DataFrame 中的所有列都转换为浮点数类型。另外,还需要检查数据中是否有缺失值,如果有,可以选择删除或者填充缺失值。最后,重新运行代码即可。
相关问题
Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 1390, in _do_pre_synchronize query.whereclause) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 39, in process return meth(clause) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 81, in visit_clauselist evaluators = list(map(self.process, clause.clauses)) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 39, in process return meth(clause) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 111, in visit_binary [clause.left, clause.right])) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 39, in process return meth(clause) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 42, in visit_grouping return self.process(clause.element) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 39, in process return meth(clause) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/evaluator.py", line 105, in visit_clauselist clause.operator) sqlalchemy.orm.evaluator.UnevaluatableError: Cannot evaluate clauselist with operator <function comma_op at 0x7fe3ed7800e0> During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/srv/srv_x6/thirdpart/easemob/chartmsg.py", line 229, in send_sys_msg_to_person yield QyWxManage(business_id=business_id, user={}).qywx_send_msg(business_id, user_id_list, customer_content=sns_alert_sys_msg_model) File "/srv/srv_x6/services/qyWX/qyWX_manage.py", line 889, in qywx_send_msg update({Employee.qywx_user_id: ""}) File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3369, in update update_op.exec_() File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 1324, in exec_ self._do_pre_synchronize() File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 1401, in _do_pre_synchronize 'synchronize_session parameter.' % err) sqlalchemy.exc.InvalidRequestError: Could not evaluate current criteria in Python: "Cannot evaluate clauselist with operator <function comma_op at 0x7fe3ed7800e0>". Specify 'fetch' or False for the synchronize_session parameter.
这个错误是由SQLAlchemy引起的。它发生在执行查询时,由于无法评估给定的条件,导致无法完成操作。具体来说,错误信息指出无法评估包含逗号操作符的clauselist。
解决这个问题的一种方法是在执行更新操作时,为`synchronize_session`参数指定'fetch'或False。这样可以避免在执行更新操作时尝试对查询结果进行评估。
例如,在你的代码中的`update()`方法中,你可以将`synchronize_session`参数设置为False,如下所示:
```python
update({Employee.qywx_user_id: ""}, synchronize_session=False)
```
这样就可以解决这个错误,并且不会尝试对查询结果进行评估。
Traceback (most recent call last): File "test03.py", line 91, in <module> main() File "test03.py", line 74, in main df = parse_data(data) File "test03.py", line 36, in parse_data df1 = pd.DataFrame([re.findall(REGEX1, data[0])], columns=columns1) File "/usr/local/python/3.8.3/lib/python3.8/site-packages/pandas/core/frame.py", line 474, in __init__ arrays, columns = to_arrays(data, columns, dtype=dtype) File "/usr/local/python/3.8.3/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 461, in to_arrays return _list_to_arrays(data, columns, coerce_float=coerce_float, dtype=dtype) File "/usr/local/python/3.8.3/lib/python3.8/site-packages/pandas/core/internals/construction.py", line 500, in _list_to_arrays raise ValueError(e) from e ValueError: 72 columns passed, passed data had 0 columns
这个错误提示说明在使用 Pandas 创建 DataFrame 时,你传递的列数与数据的列数不匹配。具体来说,这里的错误是在第36行,使用了 `pd.DataFrame` 函数创建 DataFrame。根据代码,可以看到 `re.findall` 函数返回的是一个列表,包含了匹配到的字符串。但是在传递给 `pd.DataFrame` 函数时,你使用了 `[ ]` 将这个列表包含在内,导致了传递的列数不匹配。
要解决这个问题,你可以将 `[ ]` 去掉,直接将列表作为参数传递给 `pd.DataFrame` 函数,这样就不会出现列数不匹配的问题。例如,你可以将第36行的代码修改为:
```
df1 = pd.DataFrame(re.findall(REGEX1, data[0]), columns=columns1)
```
这样应该就可以创建正确的 DataFrame 了。
阅读全文