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:ย 

Comparing schemas of two dataframes

dream
Contributor

So I was comparing schemas of two different dataframe using this code:

 

>>> df1.schema == df2.schema
Out: False

 

But the thing is, both the schemas are completely equal.

When digging deeper I realized that some of the StructFields() that should have been equal have different metadata property

 

{'name': 'customer_id', 'dataType': StringType(), 'nullable': True, 'metadata': {}}
{'name': 'customer_id', 'dataType': StringType(), 'nullable': True, 'metadata': {'scale': 0}}

 

What does this metadata property do?

Edit:

 

>>> all(str(x) == str(y) for x, y in zip(df1.schema, df2.schema))
Out: True

 

1 REPLY 1

Ajay-Pandey
Esteemed Contributor III

Hi @dream ,

In this case, you can go with dataframe.dtypes for comparing the schema or datatypes for two dataframe
Metadata store information about column properties

Ajay Kumar Pandey

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