Anuj Masand
Anuj Masand

Reputation: 359

Receiving wrong results via using sort_values() on a data-frame

dfObj = pd.DataFrame(result_list)
dfObj.columns = ['INCIDENT', 'ASSIGNED TO'"] 
dfObj.sort_values(by='ASSIGNED TO')
print(dfObj)

Output:

      INCIDENT      ASSIGNED TO  
0   INC1899203    Karun Sheemar   
1   INC1900599    Samarth Karan   
2   INC1900757     Ayushi Saini   
3   INC1900648   Rachit Rastogi   
4   INC1899084    Samarth Karan   
5   INC1899335     Yogesh Nehra   
6   INC1900688     Ayushi Saini   
7   INC1900636    Himanjali Roy   
8   INC1898703    Vedanshi Jain   

If you closely review the output, you can clearly see that data is not sorted and is messed up. I am trying to sort the data frame on the basis of the name so that I can send mail once to the concerned person using flow control.

Upvotes: 0

Views: 43

Answers (2)

Anuj Masand
Anuj Masand

Reputation: 359

dfObj.sort_values(by='ASSIGNED TO',inplace=True)

Its working fine now. Thank you everyone.

Upvotes: 0

M_S_N
M_S_N

Reputation: 2810

you should mention inplace=True while sorting or save it in new dataframe

new_df=dfObj.sort_values(by='ASSIGNED TO')

OR

dfObj.sort_values(by='ASSIGNED TO', inplace =True)

Upvotes: 2

Related Questions