dimanche 20 mars 2022

Sort dataframe by variable instead of column value

I have a dataframe that I am currently sorting by row id 8, however I want to adjust this so it sort it by a variable that contains a random number. See code below

    cosine_similarity_matrix_df.sort_values(by=['8'], ascending=False).head(11)

I want to make it so that instead of sorting the dataframe by row id 8, it sorts depending upon the random number stored in the variable called "id". I have tried to alter the code to put the variable id instead of ['8'] but this doesnt seem to work. Is there any way i can do this




Aucun commentaire:

Enregistrer un commentaire