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

data_df.loc[data_df['hotelID'] == sqlIDs[neededId] & to_integer(df.iloc[row, 6]) >= to_integer(MostRecent)]

This is the snippet that keeps getting me that error. The 'df.iloc[row, 6]' is a date and so is 'MostRecent'. I convert them to integers because if I don't it gives me a separate error

TypeError: unsupported operand type(s) for &: 'int' and 'Timestamp'

The 'data_df['hotelID']' is an int comparing to another int 'sqlIDs[neededId]'

So the whole point of this line is to find only rows with both the matching int (referred to as the neededId) and a date that is greater than the MostRecent



Solution 1:[1]

Brackets around each needed specification: data_df.loc[(data_df['hotelID'] == sqlIDs[neededId]) & (to_integer(df.iloc[row, 6]) >= to_integer(MostRecent))])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CRoss