Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.8 kB
1
Indexable
Never
--------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/indexes/base.py:3361, in Index.get_loc(self, key, method, tolerance)
   3360 try:
-> 3361     return self._engine.get_loc(casted_key)
   3362 except KeyError as err:

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/_libs/index.pyx:76, in pandas._libs.index.IndexEngine.get_loc()

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/_libs/index.pyx:108, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:5198, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:5206, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'person_who_resolved'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Input In [38], in <cell line: 21>()
     38 sample_ticket_df = pd.DataFrame(sample_ticket_data)
     40 # Call the make_recommendation function to get the recommendations for the sample ticket
---> 41 recommendations = make_recommendation(sample_ticket_df, df, label_enc)
     43 print("Recommended users for the sample ticket:")
     44 for i, rec in enumerate(recommendations[0]):

Input In [38], in make_recommendation(input_data, train_data, label_enc)
      9 def make_recommendation(input_data, train_data, label_enc):
     10     # Apply the function to the input data to get the recommendations
---> 11     input_data['recommendations'], input_data['actual_person_who_resolved'] = zip(*input_data.apply(lambda row: get_top_5_person_who_resolved(train_data, row), axis=1))
     13     # Remove duplicate values from recommendations
     14     input_data['recommendations'] = input_data['recommendations'].apply(lambda x: list(set(x)))

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/frame.py:8736, in DataFrame.apply(self, func, axis, raw, result_type, args, **kwargs)
   8725 from pandas.core.apply import frame_apply
   8727 op = frame_apply(
   8728     self,
   8729     func=func,
   (...)
   8734     kwargs=kwargs,
   8735 )
-> 8736 return op.apply()

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/apply.py:688, in FrameApply.apply(self)
    685 elif self.raw:
    686     return self.apply_raw()
--> 688 return self.apply_standard()

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/apply.py:805, in FrameApply.apply_standard(self)
    804 def apply_standard(self):
--> 805     results, res_index = self.apply_series_generator()
    807     # wrap results
    808     return self.wrap_results(results, res_index)

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/apply.py:821, in FrameApply.apply_series_generator(self)
    818 with option_context("mode.chained_assignment", None):
    819     for i, v in enumerate(series_gen):
    820         # ignore SettingWithCopy here in case the user mutates
--> 821         results[i] = self.f(v)
    822         if isinstance(results[i], ABCSeries):
    823             # If we have a view on v, we need to make a copy because
    824             #  series_generator will swap out the underlying data
    825             results[i] = results[i].copy(deep=False)

Input In [38], in make_recommendation.<locals>.<lambda>(row)
      9 def make_recommendation(input_data, train_data, label_enc):
     10     # Apply the function to the input data to get the recommendations
---> 11     input_data['recommendations'], input_data['actual_person_who_resolved'] = zip(*input_data.apply(lambda row: get_top_5_person_who_resolved(train_data, row), axis=1))
     13     # Remove duplicate values from recommendations
     14     input_data['recommendations'] = input_data['recommendations'].apply(lambda x: list(set(x)))

File /Analytics/venv/Jup/CAPE_ServicePlus_UC/model_training_building.py:50, in get_top_5_person_who_resolved(df, row, distance_metric)
     47 closest_role_name_decoded = df.iloc[closest_indices]['role_name_decoded']
     49 # Get the actual person_who_resolved, owner_user_id, and role_name value for the input ticket
---> 50 actual_person_who_resolved = row['person_who_resolved']
     51 actual_owner_user_id = row['owner_user_id']
     52 actual_role_name_encoded = row['role_name_encoded']

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/series.py:942, in Series.__getitem__(self, key)
    939     return self._values[key]
    941 elif key_is_scalar:
--> 942     return self._get_value(key)
    944 if is_hashable(key):
    945     # Otherwise index.get_value will raise InvalidIndexError
    946     try:
    947         # For labels that don't resolve as scalars like tuples and frozensets

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/series.py:1051, in Series._get_value(self, label, takeable)
   1048     return self._values[label]
   1050 # Similar to Index.get_value, but we do not fall back to positional
-> 1051 loc = self.index.get_loc(label)
   1052 return self.index._get_values_for_loc(self, loc, label)

File /Analytics/venv/CAPEANALYTICS/lib/python3.8/site-packages/pandas/core/indexes/base.py:3363, in Index.get_loc(self, key, method, tolerance)
   3361         return self._engine.get_loc(casted_key)
   3362     except KeyError as err:
-> 3363         raise KeyError(key) from err
   3365 if is_scalar(key) and isna(key) and not self.hasnans:
   3366     raise KeyError(key)

KeyError: 'person_who_resolved'