import numpy as np
import pandas as pd
from sympy import *
#数据表格
df = pd.read_csv(r'C:/Users/hanhan/PycharmProjects/pythonProject/alldata_new_sx.csv',encoding = 'gbk')
for i in range(len(df)-1):
T_xx = np.array(df['系数1'].iloc[i:i+q])
T_ss = np.array(df['系数2'].iloc[i:i+q])
M = T_xx * T_ss
看代码的话,就是读取csv数据中的两列数据,并进行相乘的时候出错!
不能将序列与非int类型'float'相乘
也就是T_xx或者是T_ss中有非int类型,将他们都打印出来查看:
print('T_xx', T_xx)
print('T_ss', T_ss)
结果:
T_xx [’1584’ ‘1580‘]
T_ss [1513 1520]
我们可以看到T_xx是字符串,然后现在就是需要将字符串转换为int类型:
T_xx = np.array(list(map(int,df['系数1'].iloc[i:i+q])))
分解出来为:
T_xx | = | list( | map(int, T_xx) | ) |
这里的T_xx就是需要转换的字符串数据。