AttributeError Traceback (most recent call last)
Cell In[121], line 2
1 #코드 컬럼 기준 오름차순 정렬
----> 2 df=df.sort_values(by=['code'], ascending=True, inplace=True)
3 #인덱스 리셋
4 df=df.reset_index(drop=True)
AttributeError: 'NoneType' object has no attribute 'sort_values'
sort_values() 함수가 DataFrame을 변경하지 않고 None을 반환하고 있어서 발생한 것입니다. inplace=True로 설정했을 때, sort_values()는 None을 반환하므로 변수에 할당할 필요가 없습니다. 즉, df에는 None이 할당되어 있습니다.
여러 줄의 코드를 한 줄로 축약할 수 있습니다. inplace=True로 설정하면 DataFrame이 직접 수정되므로 다음과 같이 작성할 수 있습니다:
python
Copy code
df.sort_values(by='code', ascending=True, inplace=True)
df.reset_index(drop=True, inplace=True)
또는 inplace=True를 사용하지 않고 새로운 DataFrame을 반환하는 방식으로 사용할 수 있습니다:
python
Copy code
df = df.sort_values(by='code', ascending=True).reset_index(drop=True)
둘 다 같은 결과를 제공합니다. 선택은 개인적인 취향이나 코드 스타일에 따라 달라집니다.
변수 저장해노혹 inplace=True해서 그럼 둘 중 하나만