Oct-25-2020, 06:21 AM
Hi,
I am a teacher and we are using python and pandas data structure. I am having trouble with this code:
Please help,
Thanks.
I am a teacher and we are using python and pandas data structure. I am having trouble with this code:
import pandas as pd numbers = pd.DataFrame([[3],[8],[4],[9],[14],[17]]) numbers.index = ["Odd", "Even", "Even", "Odd", "Even", "Odd"] # check if 0 or 1 for i in numbers: i = numbers % 2 print(i) if i == 0: numbers[1] = ["Y"] else: numbers[1] = ["N"]I get i printed correctly but when i run the if statements and trying to add new column data i get this error:
Quote:Traceback (most recent call last):
File "C:/Users/ramit/PycharmProjects/grade10A1/lesson.py", line 15, in <module>
if i == 0:
File "C:\Users\ramit\PycharmProjects\grade10A1\venv\lib\site-packages\pandas\core\generic.py", line 1326, in __nonzero__
raise ValueError(
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Please help,
Thanks.