0 votes
1 view
in Machine Learning by (12.2k points)

I have a 20 x 4000 dataframe in python using pandas. Two of these columns are named Year and quarter. I'd like to create a variable called period that makes Year = 2000 and quarter= q2 into 2000q2

Can anyone help with that?

1 Answer

0 votes
by (31.3k points)

You can use .map function to join a string with a column in the dataframe. To combine two columns, you can simply use the ‘+’ operator.

For example: 

dataframe["period"] = dataframe["Year"].map(str) + dataframe["quarter"]

Hope this answer helps.

...