[SOLVED] How to make a column matrix top side down?

Issue

I have a dataframe of 3*1 dimensions. The dataframe looks like the following:

    weights
0   4
1   13
2   91

I want to make the dataframe upside down like the following:

    weights
0   91
1   13
2   4

How can I do that?

Solution

You can convert the column to a numpy array and use an slice with a step of -1 to reverse:

df['weights'] = df['weights'].to_numpy()[::-1]

Output:

>>> df
   weights
0       91
1       13
2        4

Answered By – richardec

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *