How to sort the pandas dataframe sort all the column values in a row in ascending order and keep the NaN values at first
Example Data Frame is
2018-07-01 2018-07-02 2018-07-03 2018-07-04
cell_name
1002_NUc_Marathalli_7 0.734 0.550 NaN 0.481
1002_NUc_Marathalli_8 1.338 1.220 0.911 0.601
1002_NUc_Marathalli_9 0.330 1.180 0.754 0.631
1003_IU2_Munnekolalu_7 0.628 0.479 0.988 0.694
1003_IU2_Munnekolalu_8 5.327 6.831 8.387 9.428
The output should be in
1002_NUc_Marathalli_7 NaN 0.481 0.550 0.734
I can create another dataframe using:
df1 = pd.DataFrame(np.sort(df.values,axis=1), index=df.index, columns=df.columns)
But here the nan
values are coming at the end of the row. I want the nan
values at the first