mardi 31 octobre 2017

Why is my list assignment index out of range in my python app?

So imagine I have this code in python:

import pickle
import numpy as np
import pandas as pd
x_u = []
load_model = open('dt.plk', 'rb')
dt = pickle.load(load_model)
cuantos = int(input('cuantas observaciones: '))
x_u[0] =pd.DataFrame(np.random.randint(341, size = 1))
x_u[1] =pd.DataFrame(np.random.randint(291, size = 1))
x_u[2] =pd.DataFrame(np.random.randint(150, size = 1))
x_u[3] =pd.DataFrame(np.random.randint(301, size = 1))
x_u[4] =pd.DataFrame(np.random.randint(341, size = 1))
x_u[5] =pd.DataFrame(np.random.randint(299, size = 1))
x_u[6] =pd.DataFrame(np.random.randint(150, size = 1))
x_u[7] =pd.DataFrame(np.random.randint(301, size = 1))
ps = dt.predict(x_u)
for d in x_u[0].tolist():
    if d == 0:
        print('Se queda')
    else:
        print('Se va')

When I run it I get this error. I've been modifying the index range with no success can you figure out what it is?

Traceback (most recent call last):
File "app.py", line 8, in <module>
x_u[0] =pd.DataFrame(np.random.randint(341, size = 1))
IndexError: list assignment index out of range




Aucun commentaire:

Enregistrer un commentaire