1

The .csv file I am using will have multiple sheets (Dynamic sheet names).

I have to create dataFrames for all the sheets

The syntax I am using:

df = self.spark.read
         .option("sheetName", None)
         .option('header', 'true')
         .csv(file_path)

sheet_names = df.keys()
print(sheet_names)

Error:

'DataFrame' object has no attribute 'keys'

7
  • 1
    Does this answer your question? Reading Excel (.xlsx) file in pyspark Commented Apr 4, 2023 at 13:08
  • Possibly relevant: stackoverflow.com/questions/29615196/… Commented Apr 4, 2023 at 13:08
  • @notNull I don't know the sheet names. If I can hardcode then no prob Commented Apr 4, 2023 at 13:10
  • @SarahMesser I need to use apache spark. The answer is in c#. I can solve it in any other languages, c#, python etc. I need to use pyspark Commented Apr 4, 2023 at 13:11
  • 3
    @AdritaSharma A CSV has no sheet. It's just a plain text file where the delimtier between columns is supposed to be a comma. Commented Apr 4, 2023 at 14:14

1 Answer 1

1

You are reading a CSV file, which is a plain text file, so first of all, trying to get excel sheet names from it does not make sense.

Second, reading the CSV file returns you are spark dataframe. This dataframe, as you can see in this documentation, has no method named "keys".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.