When I try to convert some columns in a pandas dataframe from '0' and '1' to 'FALSE' and 'TRUE', pandas automatically detects dtype as boolean. I want to keep dtype as string, with the strings 'TRUE' and 'FALSE'.
booleanColumns = pandasDF.select_dtypes(include=[bool]).columns.values.tolist()
booleanDictionary = {'1': 'TRUE', '0': 'FALSE'}
pandasDF.to_string(columns = booleanColumns)
for column in booleanColumns:
pandasDF[column].map(booleanDictionary)
Unfortunately, python automatically converts dtype to boolean with the last operation. How can I prevent this?