# The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() using panda python

enter preformatted text hereHere I have data to import from a CSV file.I wrote an equation inside the class and to solve the equation data will import from the CSV file. When I run my code I got an error like "tuple indices must be integers or slices, not str" using panda python. Can anyone help me to solve this problem? I upload my code and CSV file here.

def ph_convert(time,we,h,a,w):
while time <= 30:
level = 1.1
level = float(level)
if w == 1:
ph= ((((6*we)+(1*h))/level -(4*a)))/time
else:
ph= ((6+((1*we)+(3*h))/level -(6 *a)))/time
break
while time <=60:
level = 1.25
level = float(level)
if w == 1:
ph= ((((6*we)+(1*h))/level -(4*a)))/time
else:
ph= ((6+((1*we)+(3*h))/level -(6 *a)))/time
break
print(ph)

data['time'] = data['time'].apply(time_convert)
we = data['we'].astype(float)
h = data['h'].astype(float)
a = data['a'].astype(float)
w = data['w'].astype(float)
time = data['time'].astype(float)
print(ph_convert(time,we,h,a,w))


Subset of my CSV file:

we  h   a   w   time
48.1    150 53  1   6:15:00
48.1    150 53  1   9:00:00
48.1    150 53  1   9:25:00
48.1    150 53  1   9:30:00
48.1    150 53  1   11:00:00


error:

[![enter image description here][2]][2]


while time <= 30:


You are trying to evaluate the vector time, but in python, boolean evaluations with that expression can only be done over scalars. The thing is, as time has multiple values, the Python interpreter can't figure out if the condition must hold over all of them, just one, etc.

If you want to evaluate if any of the values of time, or all the values in time you can use methods like time.any() or time.all()

You can always walk through all the items in time and perform the evaluation on them:

for t in time:
if t <= 30:
...

• ohh I will try to change it. There is another problem. I have another csv that same time with ph column. I want to apply to this ph column what I'm getting the values from my formula. I will upload my second csv. So then if I want to write use this time column mean data['time].iloc[2]-data['time'].iloc[0] = 15min or 60 min then activity level apply to the formula. I don't know how to write it properly . Can you give me any suggestion to solve this?
– awa
Dec 3, 2018 at 17:12
• Please consider up voting or accepting the answer if it has been of help. For the second question, it is worth opening another one Dec 3, 2018 at 17:14
• sure. done. I commented it.
– awa
Dec 3, 2018 at 17:19