add multiple columns to dataframe if not exist pandas

Solutions on MaxInterview for add multiple columns to dataframe if not exist pandas by the best coders in the world

showing results for - "add multiple columns to dataframe if not exist pandas"
Charline
25 Oct 2016
1cols = ['B','C','D']
2
3df = df.reindex(df.columns.union(cols, sort=False), axis=1, fill_value=0)
4print (df)
5   A  B  C  D
60  1  2  3  0
71  4  4  5  0
82  1  2  3  0
93  4  4  6  0
10