python - 用 float 为 pandas 转换列表
问题描述
这是我第一次发布问题,我是 python 新手。我试图在下面的公式中将 'list1' 和 'list2' 插入到 'x' 和 'y' 并且出现错误,例如
('无法将 1.16041.16001.16351.17491.17661.17501.17461.17471.1779 转换为数字')
import numpy as np
import pandas as pd
from scipy import stats
from pandas import *
list1 = ['1.1575', '1.1604', '1.1600', '1.1635', '1.1749', '1.1766', '1.1750', '1.1746', '1.1747', '1.1779']
list2 = ['6604.11341382', '6688.01480364', '6668.72146384', '6553.56452794', '6499.18728419', '6629.18122154', '6724.42744078', '6737.98000228', '6755.31691870', '6556.66000350']
# Method 2 (Correlation, p-value)
def pcc(x,y):
x = x - x.mean(0)
y = y - y.mean(0)
x /= x.std(0)
y /= y.std(0)
return np.mean(x*y)
x = np.array(x)
y = np.array(y)
print(linregress(x,y))
解决方案
尝试在 list1 和 2 的初始化下面添加:
list1 = [ float(z) for z in list1 ]
list2 = [ float(z) for z in list2 ]
推荐阅读
- c# - 具有选择不同计数的 EF Core GroupBy
- sql - 如何从 MS SQL 表中具有 MM/DD/YYYY 日期的单个列中减去
- apache-spark - Databricks UI 中的 Spark 提交作业无法访问现有的 Hive DB
- azure-cosmosdb - Azure CosmosDB AutoPilot 按小时计算和估算成本?
- imap - mbsync - 从 gmail 服务器但不从本地计算机删除邮件
- python - 我如何能够将 SQLAlchemy python 连接到 server.py 文件
- android - SQLite Android Update 语句不更改新列值
- python - (Python) 字节数据到字符串的转换
- c - 最小堆插入函数
- amazon-dynamodb - Dynamodb 中的非事务性属性唯一性?