I have a dataset with a list of quotes, like this
n agencyname paid(yes/not)
1 agencyA 1
2 agencyB 0
3 agencyC 0
4 agencyB 1
5 agencyA 0
6 agencyA 1
7 agencyB 1
...
I want to calculate the conversion rate of any agency, but I receive an error: this is my code:
for value in set(df["agencyname"]):
print("payd conversion rate for", value, "is:")
print(df[(df["agencyname"]==value)]["paid"].value_counts()[1]/len(df[(df["agencyname"]==value)]["paid"]))
the result it works for the first agencies but more or less in the middle I have this error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Input In [627], in <cell line: 1>()
1 for value in set(df["agencyname"]):
2 print("payd rate for", value, "is:")
----> 3 print(df[(df["agencyname"]==value)]["paid"].value_counts()[1]/len(df[(df["agencyname"]==value)]["paid"]))
File ~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/series.py:955, in Series.__getitem__(self, key)
952 key = unpack_1tuple(key)
954 if is_integer(key) and self.index._should_fallback_to_positional:
--> 955 return self._values[key]
957 elif key_is_scalar:
958 return self._get_value(key)
IndexError: index 1 is out of bounds for axis 0 with size 1