Mojtaba - 8 months ago 55

Python Question

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)

TrainDateNumeric=TrainDate.fillna(0).values

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()`

Answer

they are `numpy`

array. You have to compare in this way

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