apache-spark - 在 printschema 输出上创建数据框
问题描述
我在 parquet 文件上创建了一个数据框,现在可以看到数据框模式。现在我想在 printschema 输出之上创建数据框
df = spark.read.parquet("s3/location")
df.printschema()
输出看起来像 [(cola , string) , (colb,string)] 现在我想在 printschema 的输出上创建数据框。最好的方法是什么
添加更多关于迄今为止取得的成就的信息 -
df1 = sqlContext.read.parquet("s3://t1")
df1.printSchema()
我们得到了以下结果 -
root
|-- Atp: string (nullable = true)
|-- Ccetp: string (nullable = true)
|-- Ccref: string (nullable = true)
|-- Ccbbn: string (nullable = true)
|-- Ccsdt: string (nullable = true)
|-- Ccedt: string (nullable = true)
|-- Ccfdt: string (nullable = true)
|-- Ccddt: string (nullable = true)
|-- Ccamt: string (nullable = true)
我们要创建具有两列的数据框 - 1)colname,2)数据类型
但是如果我们运行下面的代码 -
schemaRDD = spark.sparkContext.parallelize([df1.schema.json()])
schema_df = spark.read.json(schemaRDD)
schema_df.show()
我们得到低于输出,我们在一行中获取整个列名和数据类型 -
+--------------------+------+
| fields| type|
+--------------------+------+
|[[Atp,true,str...|struct|
+--------------------+------+
寻找类似的输出
Atp| string
Ccetp| string
Ccref| string
Ccbbn| string
Ccsdt| string
Ccedt| string
Ccfdt| string
Ccddt| string
Ccamt| string
解决方案
不确定您使用的是什么语言,但在 pyspark 上我会这样做:
schemaRDD = spark.sparkContext.parallelize([df.schema.json()])
schema_df = spark.read.json(schemaRDD)
推荐阅读
- php - 在 PHP 中访问多维数组
- compilation - 我需要为另一个处理器弧重新编译吗?
- javascript - 在选择选项中显示值而不是文本
- c# - 如何访问真正的android命名空间?
- python-3.x - 如何在不创建应用程序的情况下在单独的表中创建 ForeignKey 字段
- css - 分配给 CSSStyleDeclaration.cssText 时,字体 Helvetica Neue 被转换为“Helvetica Neue”
- firebase - HeadUp Notification not working android中的背景<= 25。(在所有API目标中的前台工作)
- python - 模块“tensorflow.python.keras.api._v2.keras.layers”没有属性“CuDNNLSTM”
- c# - 相同的 Moq SetupSequence 用于不同的对象
- node.js - JSON.stringify 在迭代尝试时导致奇怪的只读字符串