0

I have been trying to resolve this for a while now, what has been asked multiple times and are all leading me to this one answered by @gcalmettes

I cannot see the date format used in the input file, finance-data.txt there since the provided link to the pastebin location is no longer available. The solution seems to depend on that specific format because it doesn't like the one I have in my input file (YYYY-MM-DD HH:MM:SS). The supplied code has this comment:

note that I'm using the time you formated into an ordinal float

Either I need to match my data to the original format in finance-data.txt, for me to use that code as-is or I need to figure out a way to convert my date format into an ordinal float. Can anyone help?

[Edit] I'm sorry @ImportanceOfBeingErnest. Here is a dump of my input data file:

head finance-data.txt

2018-01-05 09:30:00,142.58,142.76,141.5,142.03

2018-01-05 10:00:00,142.01,142.49,141.89,141.9904

2018-01-05 10:30:00,142.02,142.72,142.02,142.51

2018-01-05 11:00:00,142.525,142.75,142.3972,142.44

2018-01-05 11:30:00,142.46,142.469,141.94,142.09

2018-01-05 12:00:00,142.06,142.25,141.8,142.02

2018-01-05 12:30:00,142.0,142.28,141.94,142.06

2018-01-05 13:00:00,142.03,142.35,141.88,142.29

2018-01-05 13:30:00,142.2711,142.56,142.27,142.39

..

..

The error happens right upfront while reading my OHLC data file:

data = np.loadtxt('finance-data.txt', delimiter=',')

Traceback (most recent call last):

File "", line 1, in

File "C:\Users\Home\Anaconda2\lib\site-packages\numpy\lib\npyio.py", line 1024, in loadtxt

items = [conv(val) for (conv, val) in zip(converters, vals)]

File "C:\Users\Home\Anaconda2\lib\site-packages\numpy\lib\npyio.py", line 725, in floatconv

return float(x)

ValueError: invalid literal for float(): 2018-01-05 09:30:00

  • 1
    While it may well be that the format you have is different than the one from the question you link to, it would be necessary to provide a [mcve] of the issue you face here in order to get help with it. – ImportanceOfBeingErnest Jan 17 '18 at 08:05
  • Sorry. I have edited my question to include info on the error I get. Does that help? Seems like the np.loadtxt code is expecting a float type value instead of a date string? – Prasanna Venkatesh Jan 20 '18 at 01:20
  • So it seems the problem you have is actually how to read in a file with date specs into numpy. See [this question](https://stackoverflow.com/questions/20625774/reading-a-comma-delimited-file-with-a-date-object-and-a-float-with-python). – ImportanceOfBeingErnest Jan 20 '18 at 09:46

0 Answers0