Home > Enterprise >  how to sort the values in the dataframes
how to sort the values in the dataframes

Time:08-05

My dataframe:

enter image description here

How to sort the values like the final sorts? I don't know how to finish it by pandas.

CodePudding user response:

What you are really looking to do is concatenate columns A and B to get your number. An easy way to do this is to convert it to a string, add them together, and then convert it back to an integer.

#creating dataframe
data = dict(
A=[1, 2, 3, 4, 5, 6], B=[6, 5, 4, 2, 1, 3], values=["a", "b", "c", "d", "e", "f"])
so_data = pd.DataFrame(data)
    
so_data["final values"] = (so_data["A"].astype(str)   so_data["B"].astype(str)).astype(int)

I am now realizing that you also have the "values" col not sorted normally either. I am not sure how that is sorted, it seems like there is some missing information to me.

CodePudding user response:

the sorting is by col A & B, the rules by below, when col A is 1 and colB is 6, ,then back to colA find 6 , so colB in the same row is 3, and the values is f, when col B is 3, then back to col A to 3, so colB in the same row is 4, etc... however I don't how start the code in my logic.

  • Related