import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
df_new = pd.DataFrame(np.random.randn(5,3), columns=list('ABC'))
display(df_new)
diff_BC= []
for i in range(len(df_new)):
diff_BC.append(df_new.loc[i]['B'] - df_new.loc[i]['C'])
df_new['difference'] = diff_BC
display(df_new['difference'])
print(type(i))
I don't understand why df_new.loc[i]['B'] - df_new.loc[i]['C'] works, I think it should give an error , because type(i) is int and should use iloc.