Feb-23-2021, 08:11 PM
(This post was last modified: Feb-23-2021, 08:11 PM by eddywinch82.)
Hi rr1997,
If I change the following line Of Code, which you have provided.
From :-
Teleservices_Support.csv ?
As that is also used in the Code you provide, and I think it's absence, may be causing that KeyError.
If you have that File, The Code you provide may work now, with the change I made. But I would like to try
the Code out myself, with the other .csv File if that is okay with you ?
Eddie Winch
If I change the following line Of Code, which you have provided.
From :-
data = data.reindex(['Número do ponto de serviço autorizado','ID','VIN','Data de criação','Escalado em'])To :-
data = data.reindex(['Número do ponto de serviço autorizado','ID','VIN','Data de criação','Escalado em'], axis='columns')I now get the Error :-
Error:---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-19-b1f6520698fe> in <module>
28 dealers
29 # Merge, remove extra columns,
---> 30 data_merged = data.merge(dealers,how='left', left_on='Local_ID',right_on='Código')
31
32 data_merged
c:\python39\lib\site-packages\pandas\core\frame.py in merge(self, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
7948 from pandas.core.reshape.merge import merge
7949
-> 7950 return merge(
7951 self,
7952 right,
c:\python39\lib\site-packages\pandas\core\reshape\merge.py in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
72 validate=None,
73 ) -> "DataFrame":
---> 74 op = _MergeOperation(
75 left,
76 right,
c:\python39\lib\site-packages\pandas\core\reshape\merge.py in __init__(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, copy, indicator, validate)
650 self.right_join_keys,
651 self.join_names,
--> 652 ) = self._get_merge_keys()
653
654 # validate the merge keys dtypes. We may need to coerce
c:\python39\lib\site-packages\pandas\core\reshape\merge.py in _get_merge_keys(self)
1003 if not is_rkey(rk):
1004 if rk is not None:
-> 1005 right_keys.append(right._get_label_or_level_values(rk))
1006 else:
1007 # work-around for merge_asof(right_index=True)
c:\python39\lib\site-packages\pandas\core\generic.py in _get_label_or_level_values(self, key, axis)
1561 values = self.axes[axis].get_level_values(key)._values
1562 else:
-> 1563 raise KeyError(key)
1564
1565 # Check for duplicates
KeyError: 'Código'
Could you also upload, your other .csv File.Teleservices_Support.csv ?
As that is also used in the Code you provide, and I think it's absence, may be causing that KeyError.
If you have that File, The Code you provide may work now, with the change I made. But I would like to try
the Code out myself, with the other .csv File if that is okay with you ?
Eddie Winch