我有一个 pyspark 数据框列,其中有混合值,例如有些是字符串,有些是数字,如下所示 -
Source_ids
abc_123
1234.0
345
abc_cad
K-123
540.0
456.0
Run Code Online (Sandbox Code Playgroud)
我想删除小数部分,无论它出现在哪里。所以结果应该是
Source_ids
abc_123
1234
345
abc_cad
K-123
540
456
Run Code Online (Sandbox Code Playgroud)
我们不能将此列设置为长类型,因为它也有文本。我怎样才能实现它?
我有一个包含以下内容的数据框:
movieId / movieName / genre
1 example1 action|thriller|romance
2 example2 fantastic|action
Run Code Online (Sandbox Code Playgroud)
我想获取第二个数据帧(从第一个数据帧),其中包含以下内容:
movieId / movieName / genre
1 example1 action
1 example1 thriller
1 example1 romance
2 example2 fantastic
2 example2 action
Run Code Online (Sandbox Code Playgroud)
我们如何使用 pyspark 来做到这一点?
目前我正在使用这样的循环在每一行中生成唯一的 uuid -
df['uuid'] = df.apply(lambda x: uuid.uuid4(), axis=1)
Run Code Online (Sandbox Code Playgroud)
有没有办法在没有循环的情况下做到这一点?
我有两个 pyspark 数据框,如下所示 -
df1
id city country region continent
1 chicago USA NA NA
2 houston USA NA NA
3 Sydney Australia AU AU
4 London UK EU EU
Run Code Online (Sandbox Code Playgroud)
df2
id city country region continent
1 chicago USA NA NA
2 houston USA NA NA
3 Paris France EU EU
5 London UK EU EU
Run Code Online (Sandbox Code Playgroud)
我想根据所有列值找出 df2 中存在但 df1 中不存在的行。所以 df2 - df1 应该产生如下所示的 df_result
df_结果
id city country region continent
3 Paris France EU EU
5 London UK …Run Code Online (Sandbox Code Playgroud)