numberType
NumberInst
Type
1
Нет
Автомобиль
2
1
Автобус
3
1
Самолет
Я сделал это, чтобы разнести и дублировать строки:
Код: Выделить всё
df= df.with_columns(pl.col("NumberInst").alias("numberInstExclude"))
df= df.select(pl.exclude("numberInstExclude").repeat_by("numberType").explode())
numberType
NumberInst
Тип
NumberInstRep
1
Нет
Автомобиль
1
2
1
Автобус
1
2
1
Автобус
2
3
1
Плоскость
1
3
1
Плоскость
2
3
1
Самолет
3
Если у вас есть идея, как я могу получить "NumberInstRep".
Я хочу сделать следующее:
Код: Выделить всё
if NumberInst is None then NumberInstRep = 1
else use numberType to have NumberInstRep
Подробнее здесь: https://stackoverflow.com/questions/796 ... rect-count