Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python how to add columns to a pandas dataframe

# Basic syntax:
pandas_dataframe['new_column_name'] = ['list', 'of', 'column', 'values']

# Note, the list of column values must have length equal to the number
# 	of rows in the pandas dataframe you are adding it to.

# Add column in which all rows will be value:
pandas_dataframe['new_column_name'] = value
# Where value can be a string, an int, a float, and etc 
Source by pythonexamples.org #
 
PREVIOUS NEXT
Tagged: #python #add #columns #pandas #dataframe
ADD COMMENT
Topic
Name
9+3 =