You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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?
The text was updated successfully, but these errors were encountered: