So I have a function that sets a value in a column of a dataframe based on whether or not some string in the dataframe contains values from a list. I then want to get a count of how many rows in the dataframe have that value, but I am getting an error.
If certain conditions are met, the 'tag' column is being set equal to a list, ['date','must',glucose']. Not all of the rows meet the condition for this to happen. I want to find the number of rows where this IS being met,by analyzing the dataframe.
I have tried this:
df = data[data['tag'] == ['date','must','glucose']]
print(df)
...but that yields:
ValueError: Lengths must match to compare
I also tried this but that yields the same error:
df = data.tag == ['date','must','glucose']
If I was just comparing values, that would work, but having a list in the cell instead of a value is blowing it up. Like if the value was just 'four' and I was doing this, it wouldn't give me an error:
df = data[data.tag=='four']
Is there a way to accomplish this? Thank you!