我正在尝试更改一个非常大的 csv 文件的标题。
我使用 SparkSQL
所有标题some_string
在每个标题名称中都有,例如some_string.header_name
我的 Spark 配置conf = SparkConf().setMaster("local[*]").setAppName("readCSV")
要读取我使用的 csv 文件com.databricks.spark.csv package
logs_df = sqlContext.load(
source = "com.databricks.spark.csv",
header = 'true',
inferSchema ='true',
path = 'my_file.csv'
)
我的代码
header = logs_df.first()
schemaString = header.replace('`some_string.`','')
产生错误:
AttributeError
Traceback (most recent call last)
<ipython-input-63-ccfad59fc785> in <module>()
1255 raise AttributeError(item)
1256 except ValueError:
-> 1257 raise AttributeError(item)
1258
1259 def __setattr__(self, key, value):
AttributeError: replace
我不喜欢使用logs_df.withColumnRenamed()
,因为我有超过 200 列
非常适合任何想法如何快速有效地更改标题