본문 바로가기
ERROR

ValueError: Bin edges must be unique:

by ram_ 2023. 10. 28.

 

DataFrame의 결측치를 처리하려 구간화 하는 과정에서 발생한 에러이다. 

expense_bins = pd.qcut(df['column'], 3, labels=["Low", "Medium", "High"])

 

 

위의 코드에 .rank(method='first')를 추가해주었다. 해결되었다.

expense_bins = pd.qcut(df['column'].rank(method='first'), 3, labels=["Low", "Medium", "High"])

 

 

- 공식문서

https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.qcut.html

 

pandas.qcut — pandas 0.22.0 documentation

out : Categorical or Series or array of integers if labels is False The return type (Categorical or Series) depends on the input: a Series of type category if input is a Series else Categorical. Bins are represented as categories when categorical data is r

pandas.pydata.org

 

- 참고자료

https://stackoverflow.com/questions/20158597/how-to-qcut-with-non-unique-bin-edges

 

How to qcut with non unique bin edges?

My question is the same as this previous one: Binning with zero values in pandas however, I still want to include the 0 values in a fractile. Is there a way to do this? In other words, if I hav...

stackoverflow.com