VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-fix-valueerror-the-truth-value-of-a-series-is-ambiguous-in-pandas/

⇱ How To Fix ValueError: The truth value of a Series is ambiguous in Pandas - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How To Fix ValueError: The truth value of a Series is ambiguous in Pandas

Last Updated : 23 Jul, 2025

In this article, we will look at how to fix ValueError: The truth value of a Series is ambiguous in Pandas using Python. Here, we will use two examples to understand the problem, first, we will generate an error then we will find its solution. 

Generating Error True Value Error in Pandas using Conditional Statement

Here, we will create a series and provide some data in it. We will then print information on whether the series is empty or not.

Output:

---------------------------------------------------------------------------
ValueError  Traceback (most recent call last)
<ipython-input-8-e82a6939bd7b> in <module>
 5 series = pd.Series(data = [ 'Mumbai', 'Bangalore', 'Chennai', 'Delhi'])
 6 
----> 7 if series: # This is not allowed
 8 print('Pandas series have some value')
 9 else:

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

Solution

To check whether an object (like list, dict, etc in python) is empty (None) or not, we often use 'if object_name'. We have done the same in the above code to check if the Pandas series object is None or not. This will result in the error - ValueError: The truth value of a Series is ambiguous. To avoid this error, we can use the 'empty' attribute of the Pandas series object as shown in the below code.

Output:

Pandas series have some value

Generating error True Value Error in Pandas using Logical Operator

In the second example, we will create a Pandas DataFrame and query on individual columns (or Series) with some condition.

Output:

---------------------------------------------------------------------------
ValueError  Traceback (most recent call last)
<ipython-input-14-c200854fe0f8> in <module>
 8 })
 9 
---> 10 new_data = data[(data['Marks'] > 475) or (data['Name'] == 'Yash')] # This is not allowed
 11 new_data

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

Solution

Another popular case in which we might encounter the error is using standard Python logical operators - 'and' and 'or' between conditions. Pandas consider these as ambiguous. To avoid the error, we need to replace these logical operators with bit-wise operators. The 'and' operator will be replaced with '&' while the 'or' operator will be replaced with the pipe operator '|'. The below code modifies this condition and avoids the error.

Output:

 Name Marks
0 Rahul 530
2 Raj 515
3 Amit 490
4 Yash 465
Comment