Since he added third as an attribute, you should stop accessing columns as an attribute and always use df['third'] to avoid ambiguous behavior.
You should always get used to accessing and assigning columns with df[col_name] to avoid problems like
df.mean = some_calc()
Well, the problem here is that mean is a method for a DataFrame
So, you have rewritten the method with some calculated value.
The problem is that it was part of the design as a convenience and pandas for a data analysis book, and some early online video presentations showed it as a way to assign a new column, but subtle errors can be such that it really needs to be banned and removed IMO
Seriously, I can't stress this enough, stop referring to columns as an attribute , this is a serious bug and, unfortunately, I still see a lot of answers showing this usage
You can see that no new column has been added:
In [97]: df.third = pd.DataFrame(np.random.random((4,1))) df.columns Out[97]: Index(['a', 'b'], dtype='object')
You can see that third was added as an attribute:
In [98]: df.__dict__ Out[98]: {'_data': BlockManager Items: Index(['a', 'b'], dtype='object') Axis 1: Int64Index([0, 1, 2, 3], dtype='int64') FloatBlock: slice(0, 2, 1), 2 x 4, dtype: float64, '_iloc': <pandas.core.indexing._iLocIndexer at 0x7e73b00>, '_item_cache': {}, 'is_copy': None, 'third': 0 0 0.844821 1 0.286501 2 0.459170 3 0.243452}
You can see that you have Items , __data , Axis 1 , etc., but you also have 'third' , which is an attribute