Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16388

Order nested lists inside column

$
0
0

I have this dataset:

df = pd.DataFrame({'Name':['John', 'Rachel', 'Adam','Joe'],'Age':[95, 102, 31,np.nan],'Scores':[np.nan, [80, 82, 78], [25, 20, 30, 60, 21],np.nan]                  })

I would like to sort values inside column 'scores'.

Desired output:

 Name    Age     ScoresJohn    95.0     NaNRachel  102.0    [78,80,82]Adam    31.0     [20,21,25,30,60]Joe     NaN      NaN

I have tried the solutions from this answer, as well as the code

df.sort_values(by=["Scores"], na_position="first")

but result wasn not the deisred one.


Viewing all articles
Browse latest Browse all 16388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>