How to use pandas to find consecutive same data in time series

This should do it df[‘value_grp’] = (df.Values.diff(1) != 0).astype(‘int’).cumsum() value_grp will increment by one whenever Value changes. Below, you can extract the group results pd.DataFrame({‘BeginDate’ : df.groupby(‘value_grp’).Date.first(), ‘EndDate’ : df.groupby(‘value_grp’).Date.last(), ‘Consecutive’ : df.groupby(‘value_grp’).size(), ‘No’ : df.groupby(‘value_grp’).No.first()}).reset_index(drop=True)

Pandas Rolling Apply custom

As @BrenBarn commented, the rolling function needs to reduce a vector to a single number. The following is equivalent to what you were trying to do and help’s highlight the problem. zscore = lambda x: (x – x.mean()) / x.std() tmp.rolling(5).apply(zscore) TypeError: only length-1 arrays can be converted to Python scalars In the zscore function, … Read more

what’s the difference between ‘call/apply’ and ‘bind’ [duplicate]

bind returns a function which will act like the original function but with this predefined. It is usually used when you want to pass a function to an event handler or other async callback. call and apply will call a function immediately letting you specify both the value of this and any arguments the function … Read more

Including the group name in the apply function

I think you should be able to use the nameattribute: temp_dataframe.groupby(level=0,axis=0).apply(lambda x: foo(x.name, x)) should work, example: In [132]: df = pd.DataFrame({‘a’:list(‘aabccc’), ‘b’:np.arange(6)}) df Out[132]: a b 0 a 0 1 a 1 2 b 2 3 c 3 4 c 4 5 c 5 In [134]: df.groupby(‘a’).apply(lambda x: print(‘name:’, x.name, ‘\nsubdf:’,x)) name: a subdf: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)