列表索引超出范围处理CSV fi

2024-10-04 03:22:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有档案,得分.csv;它有13320行和3列—这些列是“timestamp”、“Score”和“label”。你知道吗

我想逐块操作数据,每个块由360行组成。如果有(score>;0.5,label==1),那么count=1(如果得到1,则不必操纵所有块),程序将跳到下一个包含360行的块。你知道吗

我有一个错误:“列表索引超出范围”

df = pd.DataFrame(dataSet, columns = 
 ['timestamp','Score','label'] )
 L=[]
 x=0
 for y,row in  df.iterrows():
   data=  row.to_dict() 
   Score=data['Score']
   label=data['label']
   L.append((Score,label))

 for i in range (0,len(L),360):
     x=x+1

    for j in range(i,360*x):

       if((L[j][0] >=0.4) and L[j][1]==1):
          TruePostive=TruePostive+1
          print("the TruePostive is in block number" ,x)

       if((L[j][0] < 0.4) and L[j][1]==1):
          TrueNegative=TrueNegative+1
          print("the TrueNegative is in block number" ,x)

       if((L[j][0] >= 0.4) and L[j][1]==0):
          FalsePositive=FalsePositive+1
          print("the FalsePositive is in block number" ,x)

       if((L[j][0] < 0.4) and L[j][1]==0):
          FalseNegative=FalsePositive+1
          print("the FalseNegative is in block number" ,x) 

  print("TruePostive=",TruePostive)
  print("TrueNegative=", TrueNegative)
  print("FalsePositive=", FalsePositive)
  print("FalseNegative=", FalseNegative)

Tags: andtheinnumberforifisblock