I am looking at the below code example:
data = {'Name': ['A', 'B', 'C', 'D'],
'Age': [1, 2, 3, 4],
}
# This is dummy data equivalent to what is read by csv
df = pd.DataFrame(data, columns = ['Name', 'Age'])
for i in range(len(df)) :
print(df.loc[i, "Name"], df.loc[i, "Age"])
Am I right to say that this is an incorrect usage of loc? Because it expects that the index label and position is the same (and in this example will work correctly).
Is it a better practice to use iloc when looping using range. Where as when looping using df.index, use loc?