cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Databricks pyspark - Find columns in xls file.

weldermartins
Honored Contributor

Hello everyone, every day I extract data into xls files but the column position changes every day. Is there any way to find these columns within the file?

Here's a snippet of my code.

df = spark.read.format("com.crealytics.spark.excel")\
  .option("header", "true")\
  .schema(schema)\
  .option("dataAddress", "'releases'!A27:D78") \
  .load("dbfs:/FileStore/tables/invoice_september.xls")
df.display()

1 ACCEPTED SOLUTION

Accepted Solutions

You can also do df.printSchema() to check. Or even dbutils.fs.head(<file_path>) to check the header's position. Docs https://docs.databricks.com/dev-tools/databricks-utils.html

View solution in original post

4 REPLIES 4

Debayan
Esteemed Contributor III

Hi, Thanks for reaching out to community.databricks.com.

Please refer and let us know if this helps, you can find column names: https://sparkbyexamples.com/pyspark/pyspark-find-datatype-column-names-of-dataframe/

You can also do df.printSchema() to check. Or even dbutils.fs.head(<file_path>) to check the header's position. Docs https://docs.databricks.com/dev-tools/databricks-utils.html

Vidula
Honored Contributor

Hi @welder martinsโ€‹ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

weldermartins
Honored Contributor

Hello, come shape. Thanks!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group