I have a data frame in python. I subtract a new data frame, named newdf, from the base data frame, named df, and want to do some calculations on the new data frame. I try the code below, but python does the calculations on the basic data frame yet!
import math
import pandas as pd
import numpy as np
from pandas import ExcelWriter
from pandas import ExcelFile
df = pd.read_csv('C:/Users/narge/Desktop/Site 1.csv')
newdf = df.loc[df['Class Name'] == 'F6']
df = pd.DataFrame(newdf)
for i in range (len(df)):
Column=df['Axle Weights (kg)'][i]
Separated_Column=Column.split('|')
Separated_Axle_Weights=list(map(float,Separated_Column))
print(Separated_Axle_Weights)
I expect to see the separated values of Axle Weights (kg) column for the new data frame which include only the F6 class Names. Below is the error I get.
Traceback (most recent call last):
File "C:/Users/narge/PycharmProjects/GDOT_WIM/Clustering.py", line 50, in <module>
tmp=df['Axle Weights (kg)'][i]
File "C:\Python3.7\lib\site-packages\pandas\core\series.py", line 868, in __getitem__
result = self.index.get_value(self, key)
File "C:\Python3.7\lib\site-packages\pandas\core\indexes\base.py", line 4375, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\_libs\index.pyx", line 81, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 89, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 987, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 993, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0
Process finished with exit code 1