【发布时间】:2022-09-22 02:15:51
【问题描述】:
我的 CSV 文件存在错误记录问题。我已经为这些文件推断/最终列数据类型。因此,每当我们通过与最终/推断的数据类型进行比较而得到不匹配的数据类型时,它应该逐行读取并删除不匹配的记录(行)。
我有以下步骤作为要求,
For example,
1.read csv line by line
2.find the datatype of each column and match with inferred column-datatype
3.if there is mismatch ,then remove the record(row)
otherwise keep all good rows in valid_record_csv file
INFERRED datatypes-column(final datatype) to compare with files.
name: string
date: date
phone: long
col1: integer
col2: double
SAMPLE INPUT csv file
Name date phone col1 col2
124 PANAMA 440894563 0.9800
BB 2022-9-23 449035667 9.08765
BB GRENADA BBCC PASS
SAMPLE OUTPUT csv file:
I have one column empty/blank, but it is having inferred/final datatype as integer. Another one with double datatype
NAME DATE PHONE col1 col2
BB 2022 449035667 9.08765
-
你只需要在 pyspark 中?你接受使用熊猫的解决方案吗?
-
@khaledkoubaa Pandas 也很好。
-
这回答了你的问题了吗? Drop rows in spark which dont follow schema
-
@Chris 感谢您的链接!但我想要 pyspark 或 python/pandas 中的解决方案
标签: python python-3.x pyspark apache-spark-sql