Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem with If- Else Conditiones, How can I resolve it?

The problem is that I want that the code shows the graph if the Value of "Recordinaciones" is > 1, and shows "No hay Recorinaciones Dobles" if <1 but I have some strange issue. Hope someone can help me!
The problem is:

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

Here it’s the code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import pandas as pd

doc = input('Ingresa el nombre del archivo: ')
print(f'Ingresaste {doc}')

df=pd.read_excel(doc+'.xlsx')
df['Recordinaciones'] = df.apply(lambda _: '', axis=1)
df['Cantidad'] = df.apply(lambda _: '', axis=1)

rcs=df[['Cliente','# Externo','Recordinaciones']].groupby(['Cliente','# Externo']).count().reset_index().sort_values(['Recordinaciones'],ascending=False)

Recoordinaciones = rcs['Recordinaciones']  
if Recoordinaciones > 1:                        # Pregunto si x es mayor a 1
    print(rcs[(rcs['Recordinaciones'] > 1)])    
else:
  print( "No hay Recorinaciones Dobles")            # cumple, ejecuto esto

Error Message

Ingresa el nombre del archivo: Test Feb
Ingresaste Test Feb

ValueError Traceback (most recent call last)
in
11
12 Recoordinaciones = rcs[‘Recordinaciones’]
—> 13 if Recoordinaciones > 1: # Pregunto si x es mayor a 1
14 print(rcs[(rcs[‘Recordinaciones’] > 1)])
15 else:

/usr/local/lib/python3.7/dist-packages/pandas/core/generic.py in nonzero(self)
1536 def nonzero(self):
1537 raise ValueError(
-> 1538 f"The truth value of a {type(self).name} is ambiguous. "
1539 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1540 )

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

enter image description here

>Solution :

try this:

Recoordinaciones = rcs.loc[rcs['Recordinaciones'] > 1]['Recordinaciones'].tolist()

if len(Recoordinaciones) == 0:
    print('no values >1')
else:
    for r in Recoordinaciones: 
        print(r)

basically the loc function receives a condition with a boolean outcome and locates the rows where this condition is met.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading