如何使用包含点/句点的列名创建火花数据框? [英] How to create spark dataframe with column name which contains dot/period?

查看:20
本文介绍了如何使用包含点/句点的列名创建火花数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表中的数据,我想将其转换为一个包含."的列名的 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()

如何制作包含."的有效火花数据框?

How do I make a valid spark dataframe which contains a "."?

注意:

  • 我不给."在列名中,代码运行良好.
  • 我想使用原生 spark 解决它,而不是使用 pandas 等

推荐答案

我已经运行了下面的代码

I have ran the below code

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

这篇关于如何使用包含点/句点的列名创建火花数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆