Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Machine Learning by (19k 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.1k 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.

Browse Categories