私は比較的新しいPysparkです。私を盗聴され Pysparkを修正できません:フィールドの長さの誤り(%d) "%(len(obj)、len(dataType.fields))
lines = sc.textFile('train.csv')
from pyspark.sql.types import *
train.csvがhereに格納されている:それは少し大きい
最初の行は列情報を含むデータの最初の行からのスキーマを設定するため
。fields = [StructField(field_name, StringType(), True) for field_name in lines.first().split(',')] # I am setting the schema here
schema = StructType(fields)
mstr_header = lines.filter(lambda l: "Country" in l) #Ihave seen the first row of the data, I want to remove it. Only the first row contains 'Country'
linesNoHeader = lines.subtract(mstr_header)
lines_df = linesNoHeader.map(lambda x: x.split(",")).toDF(schema) #make a dataframe
私は
lines_df.count()
を実行すると
、PySparkは私が間違っているつもり場所を把握することができません、
length of fields (%d)" % (len(obj), len(dataType.fields)))ValueError: Length of object (18) does not match with length of fields (17)
をというエラーがスローされます。大きなデータファイルに対する謝罪。