By mukesh tech01


2019-10-09 14:38:28 8 Comments

I want to reverse the values of a column based on a condition below,i tried lambda x::-1 but it didnt Work as i expected.

Dataframe:

UserA   Order_id  reversed_id
    A         1              5
    A         2              4
    A         2.             4
    A         2.             4
    A         3.             3
    A.        4.             2
    A.        4.             2
    A.        5.             1

I have userA , Order_id columns and i want to generate reversed_id column,please suggest on this.

1 comments

@WeNYoBen 2019-10-09 14:44:02

We can try rank

df.Order_id.rank(method='dense',ascending=False)
0    5.0
1    4.0
2    4.0
3    4.0
4    3.0
5    2.0
6    2.0
7    1.0
Name: Order_id, dtype: float64

Related Questions

Sponsored Content

23 Answered Questions

[SOLVED] Renaming columns in pandas

18 Answered Questions

[SOLVED] How to iterate over rows in a DataFrame in Pandas?

9 Answered Questions

15 Answered Questions

[SOLVED] Selecting multiple columns in a pandas dataframe

10 Answered Questions

[SOLVED] Select rows from a DataFrame based on values in a column in pandas

14 Answered Questions

[SOLVED] "Large data" work flows using pandas

11 Answered Questions

[SOLVED] How can I replace all the NaN values with Zero's in a column of a pandas dataframe

13 Answered Questions

[SOLVED] Delete column from pandas DataFrame

22 Answered Questions

[SOLVED] Adding new column to existing DataFrame in Python pandas

34 Answered Questions

[SOLVED] How do I sort a dictionary by value?

Sponsored Content