'Sorting complex dataframe in Python

i'm trying to sort in order a complex dataframe in Python. Any help is greatly appreciated!

my data looks like this:

23-AU
23-AU
23-BS
24_BS
11
23
AB 
N/A
N/A
24_BC
24BC 

How can I sort those strings in python? Thanks,



Solution 1:[1]

no dataframe here at all. its just strings... so just put it into a list and call sorted on that list.

my_strs = [ "23-AU", "23-AU", "23-BS" ]

sorted(my_strs)

Python Dataframe is a big framework with options to call it from inside the framework on the actual data. Your strings doesnt describe anything, except that they are str or objs.

Use the pandas options here: https://pandas.pydata.org/docs/reference/frame.html

start there and use the build-in Functions :)

If your data in the dataframe is compareable, use https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.eq.html

or the greater, lowerthan functions.

df = pd.DataFrame({'cost': [250, 150, 100],

               'revenue': [100, 250, 300]},

              index=['A', 'B', 'C'])
print(df)
print(df == 100)

Than you can play with the > or >= my_value even compare your dataframes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1