pandas DataFrame を反復処理し、特定の列に連続した重複がある行を削除する関数があります。その後、その列の実行中の合計をリストに返そうとしましたが、キーエラーが発生しているようです。これが何を意味するのかわかりません。
最小限のコード:
dropRows = [] #stores rows indices to drop
#Sanitize the data to get rid of consecutive duplicates
for indx, val in enumerate(df.removeConsecutives): #for all the values
if(indx == 0): #skip first indx
continue
if (val == df.removeConsecutives[indx-1]): #this is duplicate value as the last one
dropRows.append(indx)
sanitizedData = df.drop(dropRows)
#Create Timestamps based on RTC
listOfSums= [0] #first sum is zero
sum = 0 #running total of seconds for timestamps
for indx, val in enumerate(sanitizedData.removeConsecutives):
sum += sanitizedData.removeConsecutives[indx]
listOfSums.append(sum) #add running sum to list
エラートレースはこの行を指しています
listOfSums.append(sum) #add running sum to list
そして、これはエラーです
C:\Users\JohnDoe\Anaconda\lib\site-packages\pandas\index.pyd in pandas.index.IndexEngine.get_value (pandas\index.c:2987)()
C:\Users\JohnDoe\Anaconda\lib\site-packages\pandas\index.pyd in pandas.index.IndexEngine.get_value (pandas\index.c:2802)()
C:\Users\JohnDoe\Anaconda\lib\site-packages\pandas\index.pyd in pandas.index.IndexEngine.get_loc (pandas\index.c:3528)()
C:\Users\JohnDoe\Anaconda\lib\site-packages\pandas\hashtable.pyd in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:7032)()
C:\Users\JohnDoe\Anaconda\lib\site-packages\pandas\hashtable.pyd in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:6973)()
KeyError: 150L
すべてのパッケージ (pandas、numpy、SciPy など) を 1 つのインストール ファイルにインストールする iPython を使用しているため、パスに anaconda が含まれているのはそのためです。