1

I am using the following code to attempt to filter our specific rows but I am getting an error that says:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

df = pd.DataFrame(rdataset)
plane = 'axial'
contrast = 'T1'

a = []

for slices in range(0,60):
    if df['nSlices']==slices:  #---------------> Problem here ?
        path = df.loc[df['nSlices'].eq(slices) & df['Orient'].eq(plane)  & df['Contrast'].eq(contrast),'Path'].tolist()
        a.append(path)
1
  • 2
    please show an example of your dataframe and your expected output Commented Dec 25, 2019 at 22:16

1 Answer 1

1

The error appears because you are trying to compare Series object df['nSlices'] with scalar integer slices. The result of such comparsion is Series object with bool values (try to do print(df['nSlices']==slices) to see it) and you can't use it in if-statement.

To solve the problem just remove if df['nSlices']==slices: to get:

for slices in range(0,60):
    path = df.loc[df['nSlices'].eq(slices) & df['Orient'].eq(plane)  & df['Contrast'].eq(contrast),'Path'].tolist()
    a.append(path)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.