Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 446

Swapping rows within the same pandas dataframe

$
0
0

I'm trying to swap the rows within the same DataFrame in pandas.

I've tried running

a = pd.DataFrame(data = [[1,2],[3,4]], index=range(2), columns = ['A', 'B'])b, c = a.iloc[0], a.iloc[1]a.iloc[0], a.iloc[1] = c, b

but I just end up with both the rows showing the values for the second row (3,4).

Even the variables b and c are now both assigned to 3 and 4 even though I did not assign them again. Am I doing something wrong?


Viewing all articles
Browse latest Browse all 446

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>