Try:
# sample data
df = pd.DataFrame(np.arange(20).reshape(10,2), columns=['A','B'])
# random indexing, seed for repeatability
# remove seed for randomness
np.random.seed(42)
idx = np.random.rand(len(df)) < 0.5
# passing numpy array to bypass column alignment
df.loc[idx, ['A','B']] = df.loc[idx, ['B','A']].to_numpy()
Output:
A B
0 1 0
1 2 3
2 4 5
3 6 7
4 9 8
5 11 10
6 13 12
7 14 15
8 16 17
9 18 19
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…