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

Sia*_*ash 4 python python-2.7 pandas

我有这个数据框:

AB  DC
BA  WZ
DC  ZW
Run Code Online (Sandbox Code Playgroud)

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

AB CD
AB WZ
CD WZ
Run Code Online (Sandbox Code Playgroud)

谢谢!

WeN*_*Ben 6

尝试

df = df.applymap(lambda x : ''.join(sorted(list(x))))
  col1 col2
0   AB   CD
1   AB   WZ
2   CD   WZ
Run Code Online (Sandbox Code Playgroud)