Pyspark |从数据帧中分离字符串/ int值

时间:2018-05-21 05:58:43

标签: python pyspark apache-spark-sql

我有一个Spark Dataframe如下:

+---------+
|col_str_1|
+---------+
|     1|
|     2|
|     3|
|     4|
|     5|
|     6|
|     7|
|     8|
|     9|
|     a|
|     b|
|     c|
|     d|
|     e|
|     f|
|     g|
|     h|
|     1|
|     2|
|   3.0|
+---------+

我想根据请求

分隔字符串/ int / float值

例如: Req用于STRING,返回DF必须如下所示

+---------+
|col_str_1|
+---------+
|     a|
|     b|
|     c|
|     d|
|     e|
|     f|
|     g|
|     h|
+---------+

Req是Integer,返回DF必须如下

+---------+
|col_str_1|
+---------+
|     1|
|     2|
|     3|
|     4|
|     5|
|     6|
|     7|
|     8|
|     9|
|     1|
|     2|
+---------+

尝试以下步骤:

>> df = sqlContext.sql('select * from --db--.vt_prof_test') 
>> columns = df.columns[0]
>> df.select(columns).????

如何进一步,使用过滤器或地图,任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您可以选择 <ListView HeightRequest="20" HasUnevenRows="True" SeparatorColor="Red" ItemsSource="{Binding GetAssignedTask}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell > <Grid > <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Image Grid.Row="0" Grid.Column="0" Source="rsz_pnglogocom.png" /> <Label Grid.Row="0" Grid.Column="1" Text="{Binding strTaskName}" TextColor="Black" FontSize="Medium" /> <Label Grid.Row="1" Grid.Column="1" Text="{Binding intCurrCompletePercentage , StringFormat='{0}% Completed '}" Margin="0,0,10,0" TextColor="Black" /> <Label Grid.Row="1" Grid.Column="2" Margin="0,0,20,0" Text="{Binding dtStart,StringFormat='{0:MMMM dd, yyyy}'}" TextColor="Red" HorizontalOptions="Center"/> <Label Grid.Row="1" Grid.Column="3" Text="{Binding strAssignedByEmpName}" TextColor="Black" HorizontalOptions="End"/> </Grid> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>

#r "System.IO.Compression.FileSystem"

using System.IO.Compression;

根据需要设置udf参数。