If possible order of values from back all values before id
first processing values before id
and then apped values after id
:
df = df.iloc[::-1]
mask = (df.select_dtypes(object).apply(lambda x: x.str.contains('id', case=False)).any(axis=1))
m = mask.cumsum().gt(0)
df = pd.concat([df[m].agg(lambda x: '_'.join(x.dropna())).to_frame().T,
df[~m]], ignore_index=True)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…