Skip to content
Advertisement

How to sort a dataframe with strings

I got an code running that imports an excel file, and i want to be able to sort some of the data in it and write it to a new excel file. I got the code working somewhat as I want, but can’t make it sort the values as wanted… I want to sort the df from the column named “Varetekst”(Sorry for not written in english!) How can I sort the df from a column containing strings? I have tried multiple solutions and I think maybe the problem is that the column are a obj and not a str.

JavaScript

There is more to the code, where I import it and write it to an excel file. But this is where I do all the work, so this is what the code output:

JavaScript

Advertisement

Answer

Sorting does not get saved in place by default (as with pandas operations in general).

Either set inplace=True:

JavaScript

Or assign back to print_fisk if inplace is not set:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement