I have columns in my dataframe like this where the columns starting with 20 were generated dynamically.
I want to rename the columns starting with 20 to 2019_p, 2020_p, 2021_p dynamically.
How do I achieve this?
This should work:
df.select(*[col(c).alias(f"${c}_p") if c.startswith("20") else col(c) for c in df.columns])