Home > Net >  how to select column name with space in pyspark?
how to select column name with space in pyspark?

Time:01-09

avgsalary_df = spark.read.csv('/content/drive/MyDrive/BigData2021/Lecture23/datasets/data_scientist_salaries.csv', header = True)
avgsalary_df = df.selectExpr('Job Title' ,'Location', 'salary', 'spark')
avgsalary_df.show()

Here is my code but it wont return Job Title column cause of space inside name.what is incorrect?

CodePudding user response:

You need to quote column names with backticks (`).

avgsalary_df = df.select(['`Job Title`', 'Location', 'salary', 'spark'])
  •  Tags:  
  • Related