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
After i convert my predcitions from my keras-model into a dataframe it looks like one, but doesnt support the same methods and attributes like a normal dataframe. here my example, what can i do about it?
`
def CreateMetaLabelsRegression(pred_y,train_y,X_Dates):
print(pred_y[:5]) # print the array to see how they are structured
pred_y_df = pd.DataFrame(pred_y,columns = [["Profit","Loss"]])
# all of the following wont work... __
mask = np.where((pred_y_df["Profit"]>0) &(pred_y_df["Loss"]<0))
pred_y_df["Direction"] = pred_y_df["Direction"].loc[mask] =1
pred_y_df["Direction"] = np.where((pred_y_df["Profit"]>0) &(pred_y_df["Loss"]<0),1,np.nan)
train_Y_metalabels = CreateMetaLabelsRegression(pred_y,Y_Data,X_Dates)
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\frame.py in getitem(self, key)
2956 if self.columns.nlevels > 1:
2957 return self._getitem_multilevel(key)
-> 2958 return self._get_item_cache(key)
2959
2960 # Do we have a slicer (on rows)?
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
3268 res = cache.get(item)
3269 if res is None:
-> 3270 values = self._data.get(item)
3271 res = self._box_item_values(item, values)
3272 cache[item] = res
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\managers.py in get(self, item)
958 raise ValueError("cannot label index with a null key")
959
--> 960 return self.iget(loc)
961 else:
962
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\managers.py in iget(self, i)
975 Otherwise return as a ndarray
976 """
--> 977 block = self.blocks[self._blknos[i]]
978 values = block.iget(self._blklocs[i])
979 if values.ndim != 1:
TypeError: only integer scalar arrays can be converted to a scalar index
The text was updated successfully, but these errors were encountered:
to format code in github use 3 backticks before and after the code block.
the error is in your dataframe creation. You used a double list [[]] to create your columns.
change this pred_y_df = pd.DataFrame(pred_y,columns = [["Profit","Loss"]]) to this pred_y_df = pd.DataFrame(pred_y,columns = ["Profit","Loss"])
After i convert my predcitions from my keras-model into a dataframe it looks like one, but doesnt support the same methods and attributes like a normal dataframe. here my example, what can i do about it?
`
`
this is the output:
`[[3.4223695e-04 5.1086456e-05]
[3.6414166e-04 6.1540290e-05]
[3.4799695e-04 5.7447331e-05]
[3.4469913e-04 6.4573884e-05]
[3.4438877e-04 6.0803453e-05]]
TypeError Traceback (most recent call last)
in
13 pred_y_df["Direction"] = pred_y_df["Direction"].loc[mask] =1
14 display(pred_y_df.head())
---> 15 train_Y_metalabels = CreateMetaLabelsRegression(pred_y,Y_Data,X_Dates)
in CreateMetaLabelsRegression(pred_y, train_y, X_Dates)
10
11
---> 12 mask = np.where((pred_y_df["Profit"]>0) &(pred_y_df["Loss"]<0))
13 pred_y_df["Direction"] = pred_y_df["Direction"].loc[mask] =1
14 display(pred_y_df.head())
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\frame.py in getitem(self, key)
2956 if self.columns.nlevels > 1:
2957 return self._getitem_multilevel(key)
-> 2958 return self._get_item_cache(key)
2959
2960 # Do we have a slicer (on rows)?
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
3268 res = cache.get(item)
3269 if res is None:
-> 3270 values = self._data.get(item)
3271 res = self._box_item_values(item, values)
3272 cache[item] = res
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\managers.py in get(self, item)
958 raise ValueError("cannot label index with a null key")
959
--> 960 return self.iget(loc)
961 else:
962
c:\users\ben_z\appdata\local\programs\python\python37\lib\site-packages\pandas\core\internals\managers.py in iget(self, i)
975 Otherwise return as a ndarray
976 """
--> 977 block = self.blocks[self._blknos[i]]
978 values = block.iget(self._blklocs[i])
979 if values.ndim != 1:
TypeError: only integer scalar arrays can be converted to a scalar index
The text was updated successfully, but these errors were encountered: