mercredi 20 septembre 2017

Find a Pattern in Column with Pandas

This a a related with my previous question here

    Direction   Product StoreFrom   StoreTo DateYear DateMon DateDay
1   out         melon   StoreQ      StoreP  2017     06      02
2   out         cherry  StoreW      StoreO  2017     06      14
**3   out         Apple   StoreE      StoreU  2017     08      02
4   in          Apple   StoreE      StoreU  2017     08      12**
5   out         melon   StoreQ      StoreP  2017     09      02
**6   out         cherry  StoreW      StoreO  2017     10      07
7   in          cherry  StoreW      StoreO  2017     10      14**
8   in          Apple   StoreE      StoreU  2017     11      12

and want to reach

        Direction   Product StoreFrom   StoreTo DateYear DateMon DateDay TimeDiff
    1   out         melon   StoreQ      StoreP  2017     06      02      -
    2   out         cherry  StoreW      StoreO  2017     06      14      -

    5   out         melon   StoreQ      StoreP  2017     09      02      -

    8   in          Apple   StoreE      StoreU  2017     11      12      -
    9   came        Apple   StoreE      StoreU  2017     08      12      10
    10  came        cherry  StoreW      StoreO  2017     10      14      7

Program should create a new row if in Direction column out and in in consecutive order while Product StoreFrom StoreTo row are similar and delete duplicated rows.

Is there anyway to do this?

Aucun commentaire:

Enregistrer un commentaire