Fill Nan With All The Information From Previous Week
I have a dataframe that looks like: Week Store End Cap UPC 0 1 1 A 123456.0 1 1 1 B 789456.0 2 1 1 B 546879.0 3 1
Solution 1:
Lets try self merge after assigning +1 to week
out = df.merge(df.assign(Week=df['Week'].add(1)),
on=['Week','Store','End Cap'],how='left',suffixes=('','_y'))
out['UPC'] = out['UPC'].fillna(out['UPC_y'])
out = out.loc[:, df.columns]
print(out)
Week Store End Cap UPC
0 1 1 A 123456.0
1 1 1 B 789456.0
2 1 1 B 546879.0
3 1 1 C 423156.0
4 1 2 A 231567.0
5 1 2 B 456123.0
6 1 2 D 689741.0
7 2 1 A 321654.0
8 2 1 B 789456.0
9 2 1 B 546879.0
10 2 1 C 852634.0
Post a Comment for "Fill Nan With All The Information From Previous Week"