0 votes
1 view
in Machine Learning by (14.5k 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 (33.2k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !