Changing Columns in a DataFrame
You can create a new column just by assigning a value to it. The new column will be added dynamically. To store the point spread in each game, simply take the difference of the
'pts' (points) and
'opp_pts' (opposition points) columns.
.rename() method to shorten several of the column names. The
columns keyword argument expects a dictionary. The names of the existing columns are the keys and the updated names are the values.
01:37 Now, something went wrong here, and it’s a common mistake. The error tells you that the selected columns were not found in the axis. But what’s an axis? Remember that DataFrames have two dimensions: the rows and the columns.
These dimensions are the axes. The
0 axis is the rows and the
1 axis is the columns. By default, the axis is
.drop() will try to find rows with labels in the
elo_columns, and those don’t exist.
This is because, by default,
.drop() returns the modified
DataFrame. You could reassign this to the original or use the
inplace keyword argument to handle it all in one step. Now
nba_copy only has 21 columns.
Become a Member to join the conversation.