Answers for "add multiple columns to dataframe if not exist pandas"

0

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
Posted by: Guest on April-18-2021

Code answers related to "add multiple columns to dataframe if not exist pandas"

Python Answers by Framework

Browse Popular Code Answers by Language