我正在閱讀一個類似的 csv 檔案:
"ZEN","123"
"TEN","567"
現在,如果我用 regexp_replace 替換字符 E ,它不會給出正確的結果:
from pyspark.sql.functions import
row_number,col,desc,date_format,to_date,to_timestamp,regexp_replace
inputDirPath="/FileStore/tables/test.csv"
schema = StructType()
for field in fields:
colType = StringType()
schema.add(field.strip(),colType,True)
incr_df = spark.read.format("csv").option("header",
"false").schema(schema).option("delimiter", "\u002c").option("nullValue",
"").option("emptyValue","").option("multiline",True).csv(inputDirPath)
for column in incr_df.columns:
inc_new=incr_df.withColumn(column, regexp_replace(column,"E","") )
inc_new.show()
沒有給出正確的結果,它什么也沒做
注意:我有 100 列,所以需要使用 for 回圈
有人可以幫助發現我的錯誤嗎?
uj5u.com熱心網友回復:
串列理解將更整潔、更容易。我們試試看
inc_new =inc_new.select(*[regexp_replace(x,'E','').alias(x) for x in inc_new.columns])
inc_new.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/515568.html
上一篇:ReferenceError:檔案未定義-Suitescript
下一篇:檢查字串格式
