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
New Contributor III

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

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!