Mojtaba Mojtaba - 10 months ago 60
Python Question

Python compare two columns of a list

How can I compare two columns of a list in python? I already tried this, but it gives the error as described below:

import pandas as pd

TrainDate=pd.read_csv('../input/train_date.csv', delimiter=',', nrows=10, skiprows=0)

if (TrainDateNumeric[:,1] == TrainDateNumeric[:,2] ):
print ("Yes")

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()


they are numpy array. You have to compare in this way

import numpy as np
if np.allclose(Train[:,1], Train[:,2]):
    print ("Yes")