Oct-16-2020, 04:40 PM
I have a function that loops through a dataframe and then loops through the Booking Statuses (there are 6 possible) and looks to see if the value of the Booking Status matches one of the values in the array. If it matches, it sets the value of the row for the dollar amount column for that Booking Status to the value of the TotalRent column. This has been running for over a month and all of the sudden started giving me this error.
It is specifically pointing to the if df.loc[i, "BookingStatus"] == y line.
Here is the error message:
File "c:\python bc projects\eventforecastfysqlspyder.py", line 311, in calculate_rent_fields
if df.loc[i, "BookingStatus"] == y:
File "C:\Users\BCCENTER\anaconda3\envs\convention_center\lib\site-packages\pandas\core\generic.py", line 1327, in __nonzero__
f"The truth value of a {type(self).__name__} is ambiguous. "
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
It is specifically pointing to the if df.loc[i, "BookingStatus"] == y line.
Here is the error message:
File "c:\python bc projects\eventforecastfysqlspyder.py", line 311, in calculate_rent_fields
if df.loc[i, "BookingStatus"] == y:
File "C:\Users\BCCENTER\anaconda3\envs\convention_center\lib\site-packages\pandas\core\generic.py", line 1327, in __nonzero__
f"The truth value of a {type(self).__name__} is ambiguous. "
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
#loop through each row and set value of individual rent fields (Contract, Definite, T2, etc) #based on booking status - use array_booking_status (only contains those statuses in dataframe) def calculate_rent_fields(df): for i in df.index: for y in array_booking_status: if df.loc[i, "BookingStatus"] == y: df.loc[i, y] = df.loc[i, "TotalRent"] break return df