Say I have the following dataframe:
a=np.array([[10,20,30,40],[5,20,35,50],[0,5,10,15]])
b=pd.DataFrame(a, columns=["n1", "n2", "n3", "n4"])
I do the following calculation on it (difference between 1st and 2nd row):
c=b.diff(1,0)
c.loc[[1]]
And then I want to insert this row of differences (given by c.loc[[1]]
) into my dataframe b
. How do I do that? When I try, I get an error ValueError: cannot set a row with mismatched columns"