How do I use loops to write a code that subtracts the second row from the first row?
for i in range(1, 201,1):
NHA_2_pd = NHA_1_pd.iloc[i:] - NHA_1_pd.iloc[i-1:] # corrected the indentation
How do I use loops to write a code that subtracts the second row from the first row?
for i in range(1, 201,1):
NHA_2_pd = NHA_1_pd.iloc[i:] - NHA_1_pd.iloc[i-1:] # corrected the indentation
Assuming pandas here.
If you only want to subtract the second row from the first one:
NHA_2_pd = NHA_1_pd.iloc[1] - NHA_1_pd.iloc[0]
If you also want 2-3, 3-4, etc.:
NHA_2_pd = NHA_1_pd.shift() - NHA_1_pd