79275948

Date: 2024-12-12 17:01:19
Score: 1
Natty:
Report link

Using .agg with columns that are not string

Combining a few answers in this thread, I found this worked quite well when encountering columns that are not strings whilst avoiding slow lambda functions and allowing delimiters.

df['Period'] = df[['Year', 'Quarter']].astype(str).agg('-'.join, axis=1)
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: user28755543