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

时间:2020-10-03 18:43:20

标签: python pandas python-2.7

我有这个数据框:

AB  DC
BA  WZ
DC  ZW

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

AB CD
AB WZ
CD WZ

谢谢!

2 个答案:

答案 0 :(得分:6)

尝试

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

答案 1 :(得分:2)

使用:

<ListView ItemsSource="{Binding DevicesList}"
          SelectedItem="{Binding SelectedDevice, Mode=TwoWay}"
          SelectionMode="None"
          HasUnevenRows="True"
          x:Name="DeviceListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <Grid Margin="14">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0"
                               FontFamily="MaterialFont"
                               Text="{Binding Icon}"
                               FontSize="36"/>
                        <StackLayout Grid.Column="1"
                                     Margin="4,0,0,0">
                            <StackLayout Orientation="Horizontal">
                                <Label Text="{Binding Name}"
                                       FontSize="Medium"/>
                                <Label FontFamily="MaterialFont"
                                       Text="{Binding ConnectionStateIcon}"
                                       FontSize="Medium"/>
                            </StackLayout>
                            <Label Text="{Binding BluetoothDevice.Address}" FontSize="10"/>
                        </StackLayout>
                        <Label Grid.Column="2"
                               FontFamily="MaterialFont"
                               Text="{x:Static constants:IconConstants.ChevronRight}"
                               FontSize="36"
                               VerticalTextAlignment="Center"/>
                    </Grid>
                </ViewCell.View>
                <ViewCell.ContextActions>
                    <MenuItem Text="Connect"
                              Command="{Binding Source={x:Reference DeviceListView}, Path=BindingContext.ConnectDeviceCommand}"
                              CommandParameter="{Binding}"/>
                    <MenuItem Text="Delete"
                              Command="{Binding Source={x:Reference DeviceListView}, Path=BindingContext.DeleteDeviceCommand}"
                              CommandParameter="{Binding Id}"
                              IsDestructive="True"/>
                </ViewCell.ContextActions>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>