我正在使用 PySpark 并加载csv
文件。我有一列包含欧洲格式的数字,这意味着逗号替换点,反之亦然。
例如:我有2.416,67
代替2,416.67
.
My data in .csv file looks like this -
ID; Revenue
21; 2.645,45
23; 31.147,05
.
.
55; 1.009,11
在 pandas 中,可以通过指定轻松读取这样的文件decimal=','
and thousands='.'
里面的选项pd.read_csv()
阅读欧洲格式。
熊猫代码:
import pandas as pd
df=pd.read_csv("filepath/revenues.csv",sep=';',decimal=',',thousands='.')
我不知道如何在 PySpark 中完成此操作。
PySpark代码:
from pyspark.sql.types import StructType, StructField, FloatType, StringType
schema = StructType([
StructField("ID", StringType(), True),
StructField("Revenue", FloatType(), True)
])
df=spark.read.csv("filepath/revenues.csv",sep=';',encoding='UTF-8', schema=schema, header=True)
任何人都可以建议我们如何使用上述方法在 PySpark 中加载这样的文件.csv()
功能?