You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
create an additional column 'newc' of my dataframe df as df['newc'] through rolling.apply on df['cond'] with a custom function. The custom function requires two columns of df.
>>> df.head()
temp cond
ts
2018-06-01 00:00:00 51.908 27.83
2018-06-01 00:05:00 52.144 27.83
2018-06-01 00:10:00 51.880 27.83
2018-06-01 00:15:00 52.001 27.83
2018-06-01 00:20:00 51.835 27.83
def T_correction(df, d):
df = pd.DataFrame(data = df)
df.columns = ['cond']
df['temp'] = d
X = df.drop(['cond'], axis = 1) # X features: temp
X = sm.add_constant(X) # add intercept
lmodel = sm.OLS(df.cond, X) # fit cond = a + b*temp
results = lmodel.fit() #
Op = results.predict(X) # derive 'cond' as explained by temp
Tc1 = df.cond - Op # remove the linear influence
#---conditional correction --------------------------------------
Tc = np.where(df.temp > (np.mean(df.temp) + 0.5*np.std(df.temp)), df.cond, Tc1)
return Tc[-1] # returning the last value
I understand it may be related to the issue:
raise NotImplementedError('See issue #11704 {url}'.format(url=url))
NotImplementedError: See issue #11704 https://github.com/pandas-dev/pandas/issues/11704
This may not have reached high enough importance for someone to look into it. Or there may be other ways we could achieve this. I am not experienced enough with pandas code to start looking into myself but I am happy try if some guidance is available.
API breaking implications
No changes in the way we call the API
Describe alternatives you've considered
Ended up using loop - much slower
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem?
Yes.
I wish I could use pandas to:
create an additional column
'newc'
of my dataframedf
asdf['newc']
through rolling.apply ondf['cond']
with a custom function. The custom function requires two columns ofdf
.Describe the solution you'd like
I prefer the solution to look something like:
df['newc'] = df['cond'].rolling(4).apply(T_correction, args = (df['temp'].rolling(4)))
where
I understand it may be related to the issue:
This may not have reached high enough importance for someone to look into it. Or there may be other ways we could achieve this. I am not experienced enough with pandas code to start looking into myself but I am happy try if some guidance is available.
API breaking implications
No changes in the way we call the API
Describe alternatives you've considered
Ended up using loop - much slower
The text was updated successfully, but these errors were encountered: