После того, как вы выполните ffill
, вы можете вычислить порядок каждой строки с помощью groupby().cumcount()
:
df['col'] = df['col'].ffill()
orders = df.groupby('col').cumcount()
# concatenate the order except for the first rows
df['col'] = np.where(orders==0, df['col'], df['col'] + '-' + orders.astype(str))