Answers for "pandas add two string columns"

0

pandas add two string columns

# if both columns are strings, you can concatenate them directly
df["period"] = df["Year"] + df["quarter"]

# If one (or both) of the columns are not string typed, you should convert it 
# (them) first,
df["period"] = df["Year"].astype(str) + df["quarter"]
Posted by: Guest on August-31-2021

Code answers related to "pandas add two string columns"

Python Answers by Framework

Browse Popular Code Answers by Language