Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在每个单元格中对字母进行排序_Python_Pandas_Python 2.7 - Fatal编程技术网

Python 在每个单元格中对字母进行排序

Python 在每个单元格中对字母进行排序,python,pandas,python-2.7,Python,Pandas,Python 2.7,我有这个数据框: AB DC BA WZ DC ZW 我想用熊猫对每个单元格的字母进行排序,如下所示: AB CD AB WZ CD WZ 谢谢 试试看 df = df.applymap(lambda x : ''.join(sorted(list(x)))) col1 col2 0 AB CD 1 AB WZ 2 CD WZ 使用: df.applymap(lambda x: ''.join(sorted(x)))

我有这个数据框:

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

AB CD
AB WZ
CD WZ
谢谢

试试看

df = df.applymap(lambda x : ''.join(sorted(list(x))))
  col1 col2
0   AB   CD
1   AB   WZ
2   CD   WZ
使用:

df.applymap(lambda x:  ''.join(sorted(x)))