You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:按DataFrame首行值的顺序展开并排序数据

求助:按DataFrame首行值的顺序展开并排序数据

Suppose I have a DataFrame with the following format of strings separated by commas:

IndexColumnName
0apple,peach,orange,pear,
1orange, pear,apple
2pear
3peach,apple
4orange

The actual number of rows will be greater than 10,000.

I want to expand the DataFrame and sort the DataFrame by row 0.

My expected output is below, where None is of type NoneType:

Index0123
0applepeachorangepear
1appleNoneorangepear
2NoneNoneNonepear
3applepeachNoneNone
4NoneNoneorangeNone

I have expanded the data using the following code:

df = df['ColumnName'].str.split(',', expand=True)  # Expand initial DataFrame

However, I am unable to sort or reorder the data as desired despite trying various combinations of df.sort_values().

备注:内容来源于stack exchange,提问作者user29981437

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 19:13:12