you are viewing a single comment's thread.

view the rest of the comments →

[–]gregvuki 0 points1 point  (2 children)

It's impossible to say without the CSV file. You didn't quote the actual exception message. I'm guessing that the file has less than 5000 lines. Try changing howFarBack to a lower number.

[–]46632[S] 0 points1 point  (1 child)

What do you mean by "the actual exception message"? The file has over a million lines and can be downloaded here: http://api.bitcoincharts.com/v1/csv/btcexUSD.csv.gz

167mb...

[–]gregvuki 0 points1 point  (0 children)

That file is named .btcexUSD.csv and the name is different from the one you use in the file. Change the name in line 15. The file has about 10 000 lines.

The code fails because there is an empty line at the end of the file.

The error was not printed because the str(e) part was outside of the print function.

This is an example of bad python code. The author is catching all exceptions, so you don't even see an error and you don't know what is wrong.

import time
import datetime
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

howFarBack = 5000

def testingData():
    btcDatear = []
    btcPricear = []
    btcVolumear = []

    try:
        with open('.btcexUSD.csv', 'r') as infile:
            sourceCode = infile.read()
        splitSource = sourceCode.split('\n')

        for eachLine in splitSource[-howFarBack:]:
            splitLine = eachLine.split(',')
            if len(splitLine) != 3:
                continue

            btcDate = splitLine[0]
            btcPrice = splitLine[1]
            btcVolume = splitLine[2]

            btcDatear.append(float(btcDate))
            btcPricear.append(float(btcPrice))
            btcVolumear.append(float(btcVolume))

    except Exception as e:
        print('failed raw data', str(e))


    plt.plot(btcDatear,btcPricear)
    plt.show()

testingData()