'KeyError due to [missing or damaged?] row in a certain column in a dataframe

So I was doing my data analyst capstone of IBM using the csv "https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DA0321EN-SkillsNetwork/LargeData/m1_survey_data.csv". I was on my to create a new column in a data frame by iterating over the rows of the dataframe but pandas threw an error "KeyError: 1168". I was really confused so I looped over and found out that when the code is executing df.CompTotal[1168], pandas throws an error. Here's all the relevant code:

import pandas as pd
df = pd.read_csv("https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DA0321EN-SkillsNetwork/LargeData/m1_survey_data.csv")
df.drop_duplicates(inplace = True)
#length of data frame is 13398 
for i in range(len(df):
    print(i)
    print(df.CompTotal[i])

After printing i = 1668, it throws the error KeyError: 1168(it also happens to 1169 too) I looked into the csv file in Excel and found out that the row 1168 does exist. Any reason why this happens? df.CompTotal[2000] works just fine. Here's the error: enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source