Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by Henry Yik for Get the value of the precedent day in a pivot table

IIUC you can check for your conditions with pd.Series.where:

pt = raw.pivot_table(index=['GROUP_ID', 'DATE'], columns=['NAME'], values=['VALUE'])s = pt["VALUE"].groupby(level=0)["C"].shift()pt[("VALUE_PREV","C")] = s.where(s.notnull(), np.NaN)print (pt)                    VALUE            VALUE_PREVNAME                    A     B    C          CGROUP_ID DATE                                  123456   2020-07-01  10.0  25.0  0.0        NaN         2020-07-02  17.0  23.0  NaN        0.0789012   2020-07-02  11.0  19.0  NaN        NaN         2020-07-03   8.0  21.0  NaN        NaN

Viewing all articles
Browse latest Browse all 2

Trending Articles