#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목pandas 모듈의 read_excel 함수의 encoding parameter2022-05-14 17:32
작성자

import pandas as pd

pop_Seoul = pd.read_excel('..\\data\\population_in_Seoul.xls', encoding='utf-8') 


주피터랩에서 위의 코드를 실행시키면 아래와 같은 오류가 뜹니다.


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [30], in <cell line: 8>()
      1 ##with open ('..\\data\\CCTV_in_Seoul.csv', 'r', encoding='UTF-8') as file:
      2 ##    pop_Seoul = pd.read_excel(file, **other_kwargs)
      3 
      4 ##pop_Seoul = pd.read_excel('..\\data\\CCTV_in_Seoul.csv', encoding='utf-8')
      5 
      6 ##pop_Seoul = pd.read_excel('..\\data\\CCTV_in_Seoul.csv', encoding='utf-8')
----> 8 pop_Seoul = pd.read_excel('..\\data\\population_in_Seoul.xls', encoding='utf-8')

File ~\AppData\Roaming\jupyterlab-desktop\jlab_server\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    305 if len(args) > num_allow_args:
    306     warnings.warn(
    307         msg.format(arguments=arguments),
    308         FutureWarning,
    309         stacklevel=stacklevel,
    310     )
--> 311 return func(*args, **kwargs)

TypeError: read_excel() got an unexpected keyword argument 'encoding'

그래서 혹시나 해서 idle에서
help(pandas.read_excel)
을 입력해 보았더니 encoding이라는 parameter가 없는 것을 확인했습니다.
인터넷에도 검색해 보니 
https://github.com/pandas-dev/pandas/issues/35753 
에서 2020년 8월쯤에 simonjayhawkins라는 유저가
read_excel() no longer takes **kwds arguments.
라고 했고 그 아래에 twoertwein라는 유저가 
with open(path_to_excel_file, mode="r", encoding="iso-8859-1") as file:
    df = pd.read_excel(file, **other_kwargs)
와 같은 방법을 제시했는데, **kwargs 가 가변인자를 위한 변수라고 하는데 
아직 배운적이 없어서 어떤 내용을 넣어야 할지 잘 모르겠어서 질문 드립니다.

어떻게 하면 해당 엑셀 파일을 열수 있을 지 도움 주시면 감사하겠습니다.




 
댓글