Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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"]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #add #string #columns
ADD COMMENT
Topic
Name
9+2 =