df0 = pd.DataFrame() range1 = df_ssALL['a'].unique() range2 = df_ssALL['b'].unique() for i in range1: for j in range2: record = df_ssALL.loc[(df_ssALL['a']==i)&(df_ssALL['b']==j)] if len(record)<2: continue endog = record['feature1'] exog = sm.add_constant(record['feature2']) rols = RollingOLS(endog, exog, window=2) rres = rols.fit() record['const'] = rres.params['const'] record['slop'] = rres.params['feature2'] df0.append(record, ignore_index=True)
KeyError Traceback (most recent call last) /opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2894 try: -> 2895 return self._engine.get_loc(casted_key) 2896 except KeyError as err: pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() KeyError: 'const'
'const'
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)