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

.buy_and_hold float series conversion error #32

Closed
VictorHM opened this issue Jan 20, 2019 · 4 comments
Closed

.buy_and_hold float series conversion error #32

VictorHM opened this issue Jan 20, 2019 · 4 comments

Comments

@VictorHM
Copy link

Running the first examples of Stocker I got this error regarding float conversion of time series.

>>> microsoft = Stocker('MSFT')
MSFT Stocker Initialized. Data covers 1986-03-13 to 2018-03-27.
>>> microsoft.buy_and_hold(start_date='2018-01-01', end_date='2018-01-16', nshares=100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Programacion\Proyectos\WinPython\JupyterProyectos\Stocker\Data-Analysis-master\stocker\stocker.py", line 331, in buy_and_hold
    start_price = float(self.stock[self.stock['Date'] == start_date]['Adj. Open'])
  File "C:\Users\rcpoe\Anaconda3\envs\ml_env\lib\site-packages\pandas\core\series.py", line 118, in wrapper
    "{0}".format(str(converter)))
TypeError: cannot convert the series to <class 'float'>

It seems related to pandas, the version I have is 0.23.4 as I installed dependencies using conda-forge to make it work (a lot of problems from fbprophet came when I tried to use pip). I will try to find a way to fix this and report back here, but any help will be appreciated as I am quite new to Pandas (and Python in general).

@loveloud
Copy link

Hi @victor,is what you're trying to do convert series to float? if so,i think you keep getting the error because you did not import pandas;much as you have it installed, you still have to import it;
import pandas as pd
To offer any further help, what were you exactly convert, i mean which columns of data?
i hope to hear from you soon.

@VictorHM
Copy link
Author

Hi @Hackingforlife thanks for the answer. I tried as you suggested but still have the same error.

Regarding your question, I just used microsoft.buy_and_hold(start_date='2018-01-01', end_date='2018-01-16', nshares=100) that contains a conversion of some columns. It is in the library so I didn't try to convert explicitly. I can not offer more info for now until I deep more into the code, as I only skimmed through it briefly.

I think that the conversion that provokes the error is inside Stocker code, in particular it is this line that shows in the error message:
start_price = float(self.stock[self.stock['Date'] == start_date]['Adj. Open'])

I will update as soon as I have more info. Thanks!

@loveloud
Copy link

loveloud commented Jan 29, 2019 via email

@VictorHM
Copy link
Author

Updated the repo and checked the libs and the error dissapeared. Probably it was something I typed wrong.

Although, for future references, there is still this warning

'datetime.date' is coerced to a datetime. In the future pandas will
not coerce, and a TypeError will be raised. To retain the current
behavior, convert the 'datetime.date' to a datetime with
'pd.Timestamp'.```

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