我有一个数据帧,其中一列包含几个'key=value‘格式的信息。几乎有30个不同的'key=value‘可以出现在该列中将使用4列来理解( _age,_city,_sal,_tag)
id name properties
0 A {_age=10, _city=A, _sal=1000}
1 B {_age=20, _city=B, _sal=3000, tag=XYZ}
2 C {_city=BC, tag=ABC}
如何将此字符串列转换为多列?需要为它使用spark scala数据帧。
预期输出为:
id name _
假设我有100个数据帧,我如何将它组合成一个包含所有列的数据帧。我的数据帧看起来像这样,
id name marks
00 abc 70
01 def 67
02 ghi 68
03 jkl 90
id name class
00 abc A
01 def B
02 ghi B
03 jkl A
id name std
00 abc 1
01 def 2
02 ghi 3
03 jkl 4
id name city
00 abc mex
01 def nyc
02 ghi
如何联合包含不同列数的两个数据帧A和B,并为数据帧A和B中不常见的列获取空值?
我可以看到spark的unionAll不支持此操作,并抛出以下错误
org.apache.spark.sql.AnalysisException: Union can only be performed on tables with the same number of columns, but the left table has 11 columns and the right has 10;
Spark版本: 1.6.1
我是Spark ML的新手。我正在尝试使用Spark ML Pipeline来链接数据转换(将其视为ETL过程)。换句话说,我想输入一个DataFrame,执行一系列转换(每次向该数据帧添加一列),并输出转换后的DataFrame。
我研究了Python中的Pipeline文档和代码,但我不知道如何将转换后的数据集从Pipeline中提取出来。请参见以下示例(从文档中复制并修改):
from pyspark.ml import Pipeline
from pyspark.ml.feature import HashingTF, Tokenizer
# Prepare training doc
我是Spark的新手,需要使用PySpark或Spark Sql将以下输入数据帧转置为所需的输出df (从行到列)的帮助。
输入数据帧-
A B C D
1 2 3 4
10 11 12 13
......
........
所需的输出(转置)数据
A 1
B 2
C 3
D 4
A 11
B 12
C 13
D 14
....
......
如果我可以根据我们的要求旋转输入数据(列),那就更好了。