Skip to main content
PYSPARK • LESSON 11

Inspect Data Types (dtypes)

How do we view each column name alongside its inferred Spark SQL data type?

Beginner2 Minutes140 XP
🤔 THE QUESTION

How do we view each column name alongside its inferred Spark SQL data type?

💡 WHAT IS IT?

The .dtypes property provides a list of (column_name, data_type_string) pairs for all fields.

🎯 WHAT IS IT USED FOR?

Checking type casting results, verifying numeric columns before aggregations, and debugging ingestion errors.

💻 EXAMPLE
print(df.dtypes)

🎯 Mission Objectives

Practice typing production-grade PySpark code for Inspect Data Types (dtypes).

  • Access the .dtypes property
  • Verify column type assignments
  • Audit schema data types