You can cast the Bool columns with astype(str) and use a vectorized version to concatenate the columns as follows
from StringIO import StringIO
import pandas as pd
st = """
col1|col2|col3
1|hello|True
4|world|False
7|!|True
"""
df = pd.read_csv(StringIO(st), sep="|")
print("my sample dataframe")
print(df.head())
print("current columns data types")
print(df.dtypes)
print("combining all columns with mixed datatypes")
df["combined"] = df["col1"].astype(str)+" "+df["col2"]+ " " +df["col3"].astype(str)
print("here's how the data looks now")
print(df.head())
print("here are the new columns datatypes")
print(df.dtypes)
The output of the script:
my sample dataframe
col1 col2 col3
0 1 hello True
1 4 world False
2 7 ! True
current columns data types
col1 int64
col2 object
col3 bool
dtype: object
combining all columns with mixed datatypes
here's how the data looks now
col1 col2 col3 combined
0 1 hello True 1 hello True
1 4 world False 4 world False
2 7 ! True 7 ! True
here are the new columns datatypes
col1 int64
col2 object
col3 bool
combined object
dtype: object
As you can see the new combined contains the concatenate data.
Dynamic concatenation
To perform the concatenation dynamically, here's how you should edit my previous example:
from StringIO import StringIO
import pandas as pd
st = """
col1|col2|col3
1|hello|True
4|world|False
7|!|True
"""
df = pd.read_csv(StringIO(st), sep="|")
print("my sample dataframe")
print(df.head())
print("current columns data types")
print(df.dtypes)
print("combining all columns with mixed datatypes")
#df["combined"] = df["col1"].astype(str)+" "+df["col2"]+ " " +df["col3"].astype(str)
all_columns = list(df.columns)
df["combined"] = ""
for index, column_name in enumerate(all_columns):
print("current column {column_name}".format(column_name=column_name))
df["combined"] = df["combined"] + " " +df[column_name].astype(str)
print("here's how the data looks now")
print(df.head())
print("here are the new columns datatypes")
print(df.dtypes)