python - Merge values split in different columns overwriting the 0 values -
i have dataframe values split in different columns
then want merge of them result should like
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
Post a Comment