A/B Testing for ShoeFly.com True and False as Column Names

After pivoting a specific data frame, we made a boolean variable as a column. However, I cannot use them as column variables like I did here:

clicks_pivot['percent_clicked'] = clicks_pivot.True / (clicks_pivot.False + clicks_pivot.True)

This returns and error.

This is the solution.

clicks_pivot['percent_clicked'] = clicks_pivot[True] / (clicks_pivot[False] + clicks_pivot[True])

So, why can't I use clicks_pivot.True instead of clicks_pivot[True]?

Thanks in advance

The fact that the dotted attribute allows you to access columns is more of a convenience tool implemented by pandas (the real access method is via [colname]). There are also certain column names that can never be accessed by the . attribute syntax (this includes most dataframe/series methods and also includes certain python keywords/disallowed identifier names like True). So if you really want a column addressed by True you’d need to access it with df[True] as df.True will always throw an error.

1 Like