I\'m trying to do a pivot of a table containing strings as results.
import pandas as pd
df1 = pd.DataFrame({\'index\' : range(8),
\'variable1\' : [\"A\",\"A\",\
I think the best compromise is to replace on/off with True/False, which will enable pandas to "understand" the data better and act in an intelligent, expected way.
df2 = df1.replace({'on': True, 'off': False})
You essentially conceded this in your question. My answer is, I don't think there's a better way, and you should replace 'on'/'off' anyway for whatever comes next.
As Andy Hayden points out in the comments, you'll get better performance if you replace on/off with 1/0.