Python比较列表的两列

时间:2016-09-09 10:44:40

标签: python pandas

如何比较python中列表的两列?我已经尝试了这个,但它给出了如下所述的错误:

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

1 个答案:

答案 0 :(得分:1)

他们是numpy数组。你必须以这种方式进行比较

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