Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reindex columns
#6
(Feb-23-2021, 08:11 PM)eddywinch82 Wrote: Hi rr1997,

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

Hi,

sorry for the waiting time

here it is the url:

https://filebin.net/643nkv5flvy2ceb8
Reply


Messages In This Thread
Reindex columns - by rr1997 - Feb-23-2021, 03:09 PM
RE: Reindex columns - by eddywinch82 - Feb-23-2021, 03:22 PM
RE: Reindex columns - by rr1997 - Feb-23-2021, 03:52 PM
RE: Reindex columns - by eddywinch82 - Feb-23-2021, 04:22 PM
RE: Reindex columns - by eddywinch82 - Feb-23-2021, 08:11 PM
RE: Reindex columns - by rr1997 - Feb-24-2021, 02:28 PM
RE: Reindex columns - by eddywinch82 - Feb-24-2021, 03:31 PM
RE: Reindex columns - by rr1997 - Feb-24-2021, 03:52 PM
RE: Reindex columns - by eddywinch82 - Feb-24-2021, 07:18 PM
RE: Reindex columns - by rr1997 - Feb-25-2021, 02:39 PM
RE: Reindex columns - by eddywinch82 - Feb-25-2021, 02:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'int' object has no attribute 'reindex' vladponcea 3 5,570 Jan-19-2019, 03:07 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020