So the title is a bit confusing but essentially, I have a Dataframe with two columns, one for the the character ("c") and one for the character's coordinates ("loc"). I would like to sort the dataframe by the Y coordinate. So far i have managed to sort the dataframe by the X cooridate using the sort_values() function:
df = pd.DataFrame({"c":["i", "a"," d","m"], "loc":[[1, 2], [3, 3], [4, 2], [3,5]]})
df.sort_values(by=["loc"], inplace=True)
which outputs:
c loc
0 i [1, 2]
1 a [3, 3]
3 m [3, 5]
2 d [4, 2]
The output I am aiming for is:
c loc
0 i [1, 2]
2 d [4, 2]
1 a [3, 3]
3 m [3, 5]
Cycling through the dataframe and inversing the y and x values is not an option as the full dataframe will be quite large. I do think this should be possible as the new version of pd.df.sort_values() has a "key" input (link to pd.df.sort_values() documentation), but I am not sufficiently familiar with the "key" input to properly execute this.