1 回答
TA贡献1772条经验 获得超6个赞
Index.repeat按周GroupBy.cumcount数之差使用,然后按每组计数:
a = df['price_end_week'] - df['price_start_week'] + 1
df = df.loc[df.index.repeat(a)].reset_index(drop=True)
df['actual week'] = df.groupby('customer_name').cumcount() + df['price_start_week']
print (df)
customer_name price_start_week price_end_week price_value actual week
0 A 4 7 500 4
1 A 4 7 500 5
2 A 4 7 500 6
3 A 4 7 500 7
4 B 3 6 600 3
5 B 3 6 600 4
6 B 3 6 600 5
7 B 3 6 600 6
8 C 2 4 700 2
9 C 2 4 700 3
10 C 2 4 700 4
添加回答
举报