Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange Dataframe doesnt work with specific functions : #35

Closed
Baynez opened this issue Sep 30, 2019 · 1 comment
Closed

Strange Dataframe doesnt work with specific functions : #35

Baynez opened this issue Sep 30, 2019 · 1 comment

Comments

@Baynez
Copy link

Baynez commented Sep 30, 2019

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)

`

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

@BlackArbsCEO
Copy link
Owner

  1. to format code in github use 3 backticks before and after the code block.
  2. 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"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants