Locked lesson.
About this lesson
In this video, we cover how to add a new column to your data frame.
Exercise files
Download this lesson’s related exercise files.
Creating New Columns.docx57 KB Creating New Columns - Solution.docx
55.4 KB
Quick reference
Creating New Columns
It's easy to add new columns to existing DataFrames.
When to use
Use this whenever you want to add another column - or multiple columns - to an existing dataframe.
Instructions
To add a column named "Sun" with 4 rows and 1 column:
my_df["Sun"] = randn(4,1)
To do math on columns and output the result to a new "Total" column:
my_df["Total"] = my_df["Mon"] + my_df["Tues"]
Hints & tips
- my_df["Sun"] = randn(4,1)
- my_df["Total"] = my_df["Mon"] + my_df["Tues"]
Lesson notes are only available for subscribers.