How do we extract the 4-digit year prefix from an ISO date string using 1-based indexing?
substring(strCol, pos, len) extracts a sub-string starting at 1-based index pos for len characters.
Extracting date components, parsing fixed-length transaction identifiers, and area code slicing.
from pyspark.sql.functions import col, substring
df = df.withColumn("year_prefix", substring(col("event_date"), 1, 4))Practice typing production-grade PySpark code for Substring Extraction with substring().