0

While using iterrows to implement the logic takes lot of time.Can some suggest a way on how I could optimize the code with vectorized/apply()

Below is the input table..From a partition of (ITEMSALE,ITEMID),I need to populate rows with rank=1 .If any column value is null in rank=1,I need to populate the next available value in that column.This has to be done for all columns in dataset. enter image description here

Below is the output format expected

enter image description here

I have tried below logic using iterrows where am accessing values rowise.Performance is too low using this method.

enter image description here

VIDYA RENUKA
  • 91
  • 1
  • 4

1 Answers1

0

This should get you what you need

df.loc[df.loc[df['Item_ID'].isna()].groupby('Item_Sale')['Date'].idxmin()]
ArchAngelPwn
  • 2,891
  • 1
  • 4
  • 17