如何在csv文件中明智地替换行索引

时间:2019-03-12 06:49:52

标签: python

这是我在csv文件中写入数据的代码。我想更新特定索引的行。当我使用W +时,它是更新文件的所有包含的文件,我想明智地更新特定的行。

if(index==list.index(total_Rsq)and total_Rsq>MinList)  :   


   s1=list.index(total_Rsq)
   with open("D:/Krutsi_RandD/Python/NNFiles/summary1.csv", 'w+') as csvfile: 
              rows = [[ s1,NN.inputLayerSize,'-',NN.hiddenLayerSize,'-',NN.outputLayerSize , Rsquare , Rsquare1 , argument1 , argument2,list[index]]]
              csvwriter = csv.writer(csvfile)  # creating a csv writer object 
              csvwriter.writerows(rows)   # writing the data rows 
              dummy_var1=total_Rsq

else:
   with open("D:/Krutsi_RandD/Python/NNFiles/summary1.csv", 'a') as csvfile: 

               rows = [[ s1,NN.inputLayerSize,'-',NN.hiddenLayerSize,'-',NN.outputLayerSize , Rsquare , Rsquare1 , argument1 , argument2,list[index]]]
               csvwriter = csv.writer(csvfile)  # creating a csv writer object 
               csvwriter.writerows(rows)   # writing the data rows 
               dummy_var1=total_Rsq

0 个答案:

没有答案