To combine two columns of text in a Python Pandas dataframe, we get the values from the columns and combine them with operators.
For instance, we write
df["period"] = df["Year"] + df["quarter"]
to concatenate the 'Year'
and 'quarter'
values together to form the period
column.
We can also convert columns to strings with astype
by writing
df["period"] = df["Year"].astype(str) + df["quarter"]
before we do concatenation.