python - Merge values split in different columns overwriting the 0 values -


i have dataframe values split in different columns

enter image description here

then want merge of them result should like

enter image description here

i check pandas tutorial not find similar

probably not difficult running of time

you can use .max() , apply row-wise specifying axis=1

import pandas pd  # data # =========================== c1 = [0,0,0,0,2,7] c2 = [0,0,8,4,0,0] c3 = [5,3,0,0,0,0] df = pd.dataframe(dict(c1=c1,c2=c2,c3=c3))  print(df)      c1  c2  c3 0   0   0   5 1   0   0   3 2   0   8   0 3   0   4   0 4   2   0   0 5   7   0   0  # processing # ===========================  df.max(axis=1)  0    5 1    3 2    8 3    4 4    2 5    7 dtype: int64 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -