I have a 100x15 DF, comparison_df.
I have a list of tuples, (shortened version):
watchlist = [('Admiral Group', 820.0), ('3i', 4300.0), ('AstraZeneca', 7500.0),
('Ashtead Group', 920.0)]
I want to iterate through this list of tuples and find entries in my DF which meet some conditional filters:
for a, (company, target_price) in enumerate(watchlist):
companyFilter = comparison_df["Company"][((comparison_df["Mid-price (p)"] <= target_price)
| (comparison_df["Buy Ratio"] >= 0.5))
& (comparison_df["Company"] == "{}".format(company))]
print(companyFilter)
This works, but if I give the conditional statements to comparison_df["Company"], so that I can just get the company name returned, I end up with empty Series:
95 TUI
Name: Company, dtype: object
Series([], Name: Company, dtype: object)
6 AstraZeneca
Name: Company, dtype: object
90 Standard Chartered
Name: Company, dtype: object
Series([], Name: Company, dtype: object)
How can I get just the Company names out of this data? Appending .values[0] doesn't work, because there are iterations of the loop that return junk, apparently, and this throws up an error:
IndexError: index 0 is out of bounds for axis 0 with size 0
