본문 바로가기
  • Hello_
728x90
반응형

Python/Error14

[Python_Error] TypeError: list indices must be integers or slices, not tuple 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성하고자 합니다. TypeError: list indices must be integers or slices, not tuple 해당 오류는 list 형식의 데이터를 numpy처럼 사용하고자 했을 때 자주 보게 되는 오류입니다. 아래 예시와 같이 list가 2D 형태이고 첫 번째 축이 아닌 두 번째 이상 축에 인덱싱을 하고자 할 때 발생했습니다. m = [[0, 4], [1, 0], [2, 2], [3, 3], [4, 1]] m[:,1] """ --------------------------------------------------------------------------- TypeError Traceback (most rec.. 2023. 2. 15.
[Python_Error] TypeError: cannot concatenate object of type '<class 'dict'>'; only Series and DataFrame objs are valid 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성했다. TypeError: cannot concatenate object of type ''; only Series and DataFrame objs are valid 해당 오류는 pandas.concat을 활용할 경우 안에 인자의 리스트 요소 중 데이터프레임이 아니고 dictionary인 경우 발생한 오류이다. 오류가 발생했던 코드이며, 가장 밑에 "df = pd.concat([ct_dict,xray_df])" 라인에서 오류가 나왔다. xray_excel_path = './new_annotation.xlsx' for i in range(10): ct_dict = {} ct_dict['name'] = 'ct_{}'.format(.. 2023. 2. 4.
[Python_Error] TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame" 본 포스팅은 업무 중 발생했던 오류들을 어떻게 해결했는지 작성했다. TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame" 위 에러는 pandas에서 제공하는 concat 함수를 사용할 때 발생한 오류이다. concat에 입력이 리스트 혹은 튜플이 아닌 형태로 들어갈 때 위와 같은 에러 메시지가 떴다. 에러가 발생한 코드는 다음과 같다. xray_excel_path = './new_annotation.xlsx' for i in range(10): ct_dict = {} ct_dict['name'] = ['ct_{}'.format(i+1)] ct_dict['dcm_paths.. 2023. 2. 3.
[Python_Error] UnboundLocalError: local variable 'xxx' referenced before assignm 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성했다. UnboundLocalError: local variable 'img' referenced before assignment 위 오류는 'img'라는 변수가 선언이 안되었다는 얘기로 해당 변수가 누락이 되었을 때 발생하는 오류이다. 다만 일반적인 오류랑은 다른 것이 def로 함수 선언 시 그 내부에 있는 변수가 누락되었을 때 저 오류가 발생한다는 것이다. mask = [0,0,1,0,1] if 1 in mask: pass else: img = mask print(img) """ NameError Traceback (most recent call last) /WORKSPACE/test.ipynb Cell 33 in () 5 .. 2023. 1. 30.
728x90
반응형