Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

add multiple columns to dataframe if not exist pandas

cols = ['B','C','D']

df = df.reindex(df.columns.union(cols, sort=False), axis=1, fill_value=0)
print (df)
   A  B  C  D
0  1  2  3  0
1  4  4  5  0
2  1  2  3  0
3  4  4  6  0
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #multiple #columns #dataframe #exist #pandas
ADD COMMENT
Topic
Name
9+8 =