2
for i, rows in df.iterrows():
    x, y = df.iloc[rows].copy(), df.iloc[rows+1].copy()
    df.iloc[rows], df.iloc[rows+1] = y, x
    break

执行时出现错误:

位置索引器超出范围`

我在 Spyder 中的代码 完整的代码以及每次交换后要执行的操作

4

1 回答 1

0

用于iloc

print(df.iloc[[a for b in zip(df.index[::2][::-1],df.index[1::2][::-1]) for a in b]][::-1])
于 2019-02-18T03:17:56.557 回答