You need to load data from the table and delete columns that contain the value Nan. Here is my code:
import pandas import numpy as np data = pandas.read_csv('TrueOrFalse.csv') X = np.array([data['1'], data['2'], data['3'], data['4']]) for i in X[2]: if np.isnan(X[2][i]) == 'true': X[0][i] = X[0][i+1] X[1][i] = X[1][i+1] X[2][i] = X[2][i+1] X[3][i] = X[3][i+1] else: i += 1 Gives an error message:
IndexError Traceback (most recent call last) <ipython-input-70-d2187077755d> in <module>() 11 12 for i in X[2]: ---> 13 if np.isnan(X[2][i]) == 'true': 14 X[0][i] = X[0][i+1] 15 X[1][i] = X[1][i+1] IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices Solution: data = data.dropna() . Through the loop you can and do not go through the array, it is easier to load data from a pre-sorted DataFrame.
TrueOrFalse.csvupload somewhere and give a link? - Alexander Braginisnanwith a string? - andreymali, but an index of an element in an array, that is, you meantfor i in range(len(X[2]))(but I don’t know if it works with numpy, I haven't tried it) - andreymal