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

List out of index #11

Open
Cipher4all opened this issue Aug 24, 2019 · 1 comment
Open

List out of index #11

Cipher4all opened this issue Aug 24, 2019 · 1 comment

Comments

@Cipher4all
Copy link

I copied the file and run it in the kernel. It is showing error at line 14 that list out of index range. Why that's so?

@Mohswalm545
Copy link

the code assumes that each row in the CSV file contains at least two elements (date and price). However, if the row is empty or does not have enough elements, this error will occur.

To resolve this issue, you can add some error handling to check if a row has the necessary elements before trying to access them. Here's an updated version of the get_data function that includes error handling:

python

def get_data(filename):
with open(filename, 'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader)
for row in csvFileReader:
if len(row) >= 2:
dates.append(int(row[0].split('-')[0]))
prices.append(float(row[1]))
return

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