Use a temporary varaible to store the value using .copy()
, because you are changing the values while assigning them on chain i.e. Unless you use copy the data will be changed directly.
a = pd.DataFrame(data = [[1,2],[3,4]], index=range(2), columns = ['A', 'B'])
b, c = a.iloc[0], a.iloc[1]
temp = a.iloc[0].copy()
a.iloc[0] = c
a.iloc[1] = temp
Or you can directly use copy like
a = pd.DataFrame(data = [[1,2],[3,4]], index=range(2), columns = ['A', 'B'])
b, c = a.iloc[0].copy(), a.iloc[1].copy()
a.iloc[0],a.iloc[1] = c,b
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…