Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: fonction parcourt en largeure sur un graphe 
Python :: To obtain the latest released version of statsmodels using pip: 
Python :: how to form a list from a file in python 
Python :: tkinter textbox enable only 1 line 
Python :: quadre 
Python :: introduction to sets python3 
Python :: elevando numero ao quadrado em python 
Python :: how to delete a cell in jupyter notebook 
Python :: Circular heatmap python 
Python :: uninstall python 2.7 in ubuntu 
Python :: identify color sequence with OpenCV 
Python :: response.url SSL warning python 
Python :: ev. DJANGO CREATE ACC 
Python :: turn off subplot 
Python :: subprocess ffmpeg x265 codec 
Python :: Find python background process id 
Python :: image.show pillow mac os 
Python :: is file a keywoard in python 
Python :: exercise of python loops 
Python :: matplotlib librosa show spectrogram 
Python :: Adam RMSprop Adagrad. 
Python :: instal django impoer expor 
Python :: print function in python 
Python :: python open multiple .py windows 
Python :: how to access range of tuples in python 
Python :: Python - Cómo Jugar archivo Mp3 
Python :: get opnly second part of multiindex 
Python :: credential not provided when i try to sign up a new user django 
Python :: how to use rbind() to combine dataframes 
Python :: compare if 2 numbers are relatively equal 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =