Pandas allow for many methods for adding and dropping content. We have covered how to drop a column and how to drop a row in pandas dataframe. What if you want to add a column to pandas? You can handle that in a few simple steps.
Add your first column in a pandas dataframe
# Create a dataframe in pandas df = pd.DataFrame() # Create your first column df['team'] = ['Manchester City', 'Liverpool', 'Manchester'] # View dataframe df
Now add more data to your columns in your pandas dataframe.
We can now assign wins to our teams.
# Add a new column to your dataframe called 'wins' df.assign(age = [41, 40, 21])
Full code for you to use:
https://gist.github.com/craine/0d7ef86ac02347280be9fadd4e3f366c