Wolfeatspotatoes
Wolfeatspotatoes

Reputation: 135

How to set multiple conditions in python

I wanted to specify two conditions in selecting my data. This is my code

data = np.genfromtxt("ca1_data/mrtfares.csv",
               delimiter=',',skip_header=1,
               dtype=[('Fare_Type','U50'),('Applicable_Time','U50'),('Distance','U50'),('Fare_per_Ride','i8')],
               missing_values=['na','-'],filling_values=[0])

x_adultcard = data[data['Fare_Type']=='Single trip' and data['Applicable_Time']=='All timings']['Distance']
y_adultcard = data[data['Fare_Type']=='Single trip' and data['Applicable_Time']=='All timings']['Fare_per_Ride']

But i am getting this error

---> 14 x_adultcard = data[data['Fare_Type']=='Single trip' and data['Applicable_Time']=='All timings']['Distance']
     15 y_adultcard = data[data['Fare_Type']=='Single trip' and data['Applicable_Time']=='All timings']['Fare_per_Ride']
     16 

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

This might be a very obvious answer? I am just starting to learn python so i do not know much. Thanks in advance!

Upvotes: 0

Views: 97

Answers (1)

Rotem Tal
Rotem Tal

Reputation: 769

for numpy arrays use & as and, | as or

Upvotes: 1

Related Questions