當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pyspark DataFrameReader.json用法及代碼示例

本文簡要介紹 pyspark.sql.DataFrameReader.json 的用法。

用法:

DataFrameReader.json(path, schema=None, primitivesAsString=None, prefersDecimal=None, allowComments=None, allowUnquotedFieldNames=None, allowSingleQuotes=None, allowNumericLeadingZero=None, allowBackslashEscapingAnyCharacter=None, mode=None, columnNameOfCorruptRecord=None, dateFormat=None, timestampFormat=None, multiLine=None, allowUnquotedControlChars=None, lineSep=None, samplingRatio=None, dropFieldIfAllNull=None, encoding=None, locale=None, pathGlobFilter=None, recursiveFileLookup=None, allowNonNumericNumbers=None, modifiedBefore=None, modifiedAfter=None)

加載 JSON 文件並將結果作為 DataFrame 返回。

默認支持JSON Lines (newline-delimited JSON)。對於 JSON(每個文件一條記錄),將 multiLine 參數設置為 true

如果未指定schema 參數,則此函數通過輸入一次以確定輸入模式。

1.4.0 版中的新函數。

參數

path字符串、列表或RDD

string 表示 JSON 數據集的路徑,或路徑列表,或存儲 JSON 對象的字符串的 RDD。

schema pyspark.sql.types.StructType 或 str,可選

輸入模式的可選 pyspark.sql.types.StructType 或 DDL 格式的字符串(例如 col0 INT, col1 DOUBLE )。

其他參數

Extra options

有關額外選項,請參閱您使用的版本中的Data Source Option

例子

>>> df1 = spark.read.json('python/test_support/sql/people.json')
>>> df1.dtypes
[('age', 'bigint'), ('name', 'string')]
>>> rdd = sc.textFile('python/test_support/sql/people.json')
>>> df2 = spark.read.json(rdd)
>>> df2.dtypes
[('age', 'bigint'), ('name', 'string')]

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.sql.DataFrameReader.json。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。