如何创建包含点/句点的列名称的spark数据框? [英] How to create spark dataframe with column name which contains dot/period?
本文介绍了如何创建包含点/句点的列名称的spark数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在列表中有数据,并希望将其转换为带有包含."的列名称之一的spark数据框.
I have data in a list and want to convert it to a spark dataframe with one of the column names containing a "."
我写了下面的代码,没有任何错误.
I wrote the below code which ran without any errors.
input_data = [('retail', '2017-01-03T13:21:00', 134),
('retail', '2017-01-03T13:21:00', 100)]
rdd_schema = StructType([StructField('business', StringType(), True), \
StructField('date', StringType(), True), \
StructField("`US.sales`", FloatType(), True)])
input_mock_df = spark.createDataFrame(input_mock_rdd_map, rdd_schema)
下面的代码返回列名
input_mock_df.columns
但是此数据帧上的任何操作都给出了错误
But any operations on this dataframe is giving error for example
input_mock_df.count()
如何制作包含."的有效Spark数据框?
How do I make a valid spark dataframe which contains a "."?
注意:
- 我不给."在列名称中,代码可以完美运行.
- 我想使用本机Spark来解决它,而不要使用pandas等
推荐答案
我已经运行了以下代码
input_data = [('retail', '2017-01-03T13:21:00', 134),
('retail', '2017-01-03T13:21:00', 100)]
rdd_schema = StructType([StructField('business', StringType(), True), \
StructField('date', StringType(), True), \
StructField("US.sales", IntegerType(), True)])
input_mock_df = sqlContext.createDataFrame(input_data, rdd_schema)
input_mock_df.count()
,将计数返回为2可以正常工作.请尝试答复
and it works fine returning the count as 2. Please try and reply
这篇关于如何创建包含点/句点的列名称的spark数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文