shift converts my column from integer to float. It turns out that np.nan is float only. Is there any ways to keep shifted column as integer?
shift
np.nan
You can construct a numpy array by prepending a 0 to all but the last element of column a
numpy
0
a
df.assign(b=np.append(0, df.a.values[:-1])) a b 0 0 0 1 1 0 2 2 1 3 3 2 4 4 3