对 pandas 中每个单元格内的字母进行排序

我有这个数据框:

AB  DC
BA  WZ
DC  ZW

我想使用 pandas 对每个单元格的字母进行排序,如下所示:

AB CD
AB WZ
CD WZ

谢谢!


慕丝7291255
浏览 68回答 2
2回答

摇曳的蔷薇

尝试df = df.applymap(lambda x : ''.join(sorted(list(x))))  col1 col20   AB   CD1   AB   WZ2   CD   WZ

拉风的咖菲猫

使用:df.applymap(lambda x:  ''.join(sorted(x)))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python