KeyError问题求助
生活随笔
收集整理的這篇文章主要介紹了
KeyError问题求助
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本人在對兩個Excel表格數據合并后進行t檢驗時出現KeyError報錯,提示為Excel表格每一列的名稱,如“GG”等,請問該如何解決???
代碼如下:
import pandas as pd import numpy as np from sklearn.utils import shuffle from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LassoCV from sklearn.model_selection import train_test_split,cross_val_score,KFold,RepeatedKFold,GridSearchCV from scipy.stats import pearsonr,ttest_ind,levene from sklearn.ensemble import RandomForestClassifier from sklearn import svmxlsx1_filePath="C:/Users/Administrator/Desktop/EE.xlsx" xlsx2_filePath="C:/Users/Administrator/Desktop/FF.xlsx" data_1=pd.read_excel(xlsx1_filePath) data_2=pd.read_excel(xlsx2_filePath) rows_1,__=data_1.shape rows_2,__=data_2.shape data_1.insert(0,"label",[0]*rows_1) data_2.insert(0,"label",[1]*rows_2) data=pd.concat([data_1,data_2]) data=shuffle(data) data=data.fillna(0) x=data[data.columns[1:]] y=data["label"] colNames=x.columns x=x.astype(np.float64) x=StandardScaler().fit_transform(x) x=pd.DataFrame(x) x.columns=colNamesindex=[] for colName in data.columns[1:]:if levene(data_1[colName],data_2[colName])[1]>0.05:if ttest_ind(data_1[colName],data_2[colName])[1]<0.05:index.append(colName)else:if ttest_ind(data_1[colName],data_2[colName],equal_var=False)[1]<0.05:index.append(colName) print(len(index))?
?
?
總結
以上是生活随笔為你收集整理的KeyError问题求助的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【摄影补光灯调光驱动方案】低亮度无频闪无
- 下一篇: 华为给了机会,为什么OV却没抓住?