I'm trying to write a portion of code to look up for a specific value (string) into a spefici column of a table (loaded from a .csv file). While running the code i get the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Here below the Data loaded from the .csv file:
Nome Cognome Socio Date In Date Out
0 Nicola Bonini si 03/09/1985 NaN
1 Carlo Besozzi si 24/11/1985 NaN
2 Andrea Massa no 23/06/2018 17/03/2020
3 Fabio Murazzi si 30/04/1927 NaN
I want to look for if a specific name exixst into the column "Nome".
I'm using Python 3.9 and Anaconda-Spyder IDE. Running on OS Windows 10 Pro.
Here my code
import pandas as pd
import numpy as np
lista_soci = pd.read_csv (r'C:\Users\nicola.bonini\Desktop\Python\Esercizi_Python\lista_soci.csv', sep = ';')
nome = lista_soci[["Nome"]]
nome_2 = 'Nicola'
for i in nome:
if (nome == nome_2).all():
print ('è un socio')
else:
print ('non è un socio')
The variable i'm using is nome_2, and i would look for it in "lista_soci".
Thanks for support.
Nicola