They are the same as if you were referring to the same column with a simple name, but you can do more with a musical bracket. You can only use df.col if the column name is a valid Python identifier (for example, it does not contain spaces or other similar materials). In addition, you may encounter surprises if your column name collides with the pandas method name (e.g. sum ). In parentheses, you can select multiple columns (for example, df[['col1', 'col2']] ) or add a new column ( df['newcol'] = ... ) that cannot be done using point access.
The other question you are referring to applies, but this is a much more general question. Python objects determine how operators are applied to them . and [] . pandas DataFrames decided to make them the same for this limited case of accessing individual columns with the caveats described above.
Brenbarn
source share