I have a dataframe with six different labels: presence, x, y, vx, vy and lane. I would like to differentiate between two row indices over a range of columns [x, y, vx, vy]. However, subtracting gives me NaN. Thanks for the help.
import pandas as pd
data = {'presence': [1, 1, 0, 1],
'x': [17, 35, 46, 57],
'y': [4, 4, 8, 0],
'vx': [2, 5, 9, 12],
'vy': [0.3, 0.5, 0.2, 0],
'lane': [0, 1, 2, 0]}
df = pd.DataFrame(data)
a = df.iloc[[2]]
b = df.iloc[[1]]
diff_x = b[['x','y']] - a[['x','y']] # Gives two rows and two columns of nan
# Expected output: 11 4