I have a data frame in following format with a time series
A B C 201401 201402 201403
a1 b1 c1 100 200 300
a2 b2 c2 0 250 0
I have used Pandas.melt to flatten this data and have got following format.
A B C YYYYMM Value
a1 b1 c1 201401 100
a1 b1 c1 201402 200
a1 b1 c1 201403 300
a2 b2 c2 201401 0
a2 b2 c2 201402 250
a2 b2 c2 201403 0
Now for a particular combination of [A B C] I only want the time series starting from non zero values.so my output should be like this.
A B C YYYYMM Value
a1 b1 c1 201401 100
a1 b1 c1 201402 200
a1 b1 c1 201403 300
a2 b2 c2 201402 250
a2 b2 c2 201403 0
I tried,
df.groupby(['A','B','C']).apply(lambda x: x['Value'][np.where(x['Value']>0)[0][0]:]
This just gives me time series and doesn't imply inplace changes. What should I do to achieve this?