I have a dataframe of 500 rows. I want to sort it by the column "ESG Combined Score 2011" and did that (see below). The problem is, that it sorts only by this last column and doesn't change the corresponding companies and market cap. That means that the first 2 columns doesn't change based on the last column (All columns should be sticked together). I just want to sort the companies by it's ESG Combined Score. What should I do here?
Many Thanks in advance
My code for this operation and the corresponding output
Before, I extract these three columns out of my dataset (which contains 50 columns and 500 rows):
df = pd.DataFrame(data=dataset)
df1 = df[['Company Common Name', 'Company Market Capitalization', 'ESG Combined Score 2011']]
The output before I sort the last column ("ESG Combined Score")
df1
Company Common Name Company Market Capitalization ESG Combined Score 2011
0 SSR Mining Inc 3.129135e+09 32.817325
1 Fluor Corp 3.958424e+09 69.467729
2 CBRE Group Inc 2.229251e+10 59.632423
3 Assurant Inc 8.078239e+09 46.492803
4 CME Group Inc 6.269954e+10 42.469682
5 Peabody Energy Corp 3.842130e+09 73.374671
Code I used for sorting:
sorted_2011 = df1.sort_values(by= ['ESG Combined Score 2011'], ascending=False)
Output after that:
Company Common Name Company Market Capitalization ESG Combined Score 2011
0 SSR Mining Inc 3.129135e+09 88.881182
1 Fluor Corp 3.958424e+09 85.249202
2 CBRE Group Inc 2.229251e+10 84.357820
3 Assurant Inc 8.078239e+09 84.191950
4 CME Group Inc 6.269954e+10 82.592251
5 Peabody Energy Corp 3.842130e+09 81.509097
As you can see, the last column is sorted which is fine. BUT the first 2 columns are the same as before (which should not be the case) In fact the 88.88 score corresponds to the Company "Texas Instruments Inc." and not "SSR Mining" like in the example above.
What is wrong here?