Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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 在SPARK上将JSON对象转换为数据帧_Python_Json_Apache Spark_Dataframe_Ibm Cloud - Fatal编程技术网

Python 在SPARK上将JSON对象转换为数据帧

Python 在SPARK上将JSON对象转换为数据帧,python,json,apache-spark,dataframe,ibm-cloud,Python,Json,Apache Spark,Dataframe,Ibm Cloud,我在IBMBlueMix上使用ApacheSpark上的Python笔记本收到JSON格式的推特流。我想将JSON对象转换为数据帧。我发现的最接近的东西是: json_obj={“tweet”:“嘿,伙计”,“name”:“Alan”}模拟示例 tweetsDF=sqlContext.read.json(“文件路径”) 现在,我不想加载文件。我只想把这个JSON变量转换成数据帧格式。这样我就可以将其应用于tweets变量。你知道怎么做吗?谢谢大家! 首先将JSON对象转换为RDD[String]

我在IBMBlueMix上使用ApacheSpark上的Python笔记本收到JSON格式的推特流。我想将JSON对象转换为数据帧。我发现的最接近的东西是:

json_obj={“tweet”:“嘿,伙计”,“name”:“Alan”}模拟示例

tweetsDF=sqlContext.read.json(“文件路径”)


现在,我不想加载文件。我只想把这个JSON变量转换成数据帧格式。这样我就可以将其应用于tweets变量。你知道怎么做吗?谢谢大家!

首先将JSON对象转换为RDD[String],然后应用'sqlContext.read.JSON'。下面是Scala中的示例代码

val json_obj = sc.parallelize(Array("""{"tweet": "hey man", "name": "Alan"}""", """{"tweet": "what's up", "name": "Bertha"}"""))
val tweetsDF = sqlContext.read.json(json_obj)
tweetsDF.show()
//+------+---------+
//|  name|    tweet|
//+------+---------+
//|  Alan|  hey man|
//|Bertha|what's up|
//+------+---------+

首先将JSON对象转换为RDD[String],然后应用'sqlContext.read.JSON'。下面是Scala中的示例代码

val json_obj = sc.parallelize(Array("""{"tweet": "hey man", "name": "Alan"}""", """{"tweet": "what's up", "name": "Bertha"}"""))
val tweetsDF = sqlContext.read.json(json_obj)
tweetsDF.show()
//+------+---------+
//|  name|    tweet|
//+------+---------+
//|  Alan|  hey man|
//|Bertha|what's up|
//+------+---------+