numpy 1.23.4
python 3.10.7
Предположим, у нас есть ряд упорядоченных категориальных данных:
Код: Выделить всё
s = pd.Series(['zero','one','two','three','four','five','six'], dtype='category')
s = s.cat.reorder_categories(['zero','one','two','three','four','five','six'], ordered=True)
print(s)
Код: Выделить всё
0 zero
1 one
2 two
3 three
4 four
5 five
6 six
dtype: category
Categories (7, object): ['zero' < 'one' < 'two' < 'three' < 'four' < 'five' < 'six']
Код: Выделить всё
df = pd.concat([s, s.clip(lower='two'), s.clip(upper='four'), s.clip(lower='two', upper='four')], axis=1)
print(df)
Код: Выделить всё
0 1 2 3
0 zero two zero four
1 one two one four
2 two two two four
3 three three three two
4 four four four two
5 five five four two
6 six six four two
Также я заметил, что замена значений для low=..., Upper=... не дает результата. изменить результат. См.:
Код: Выделить всё
pd.concat([s.clip(lower='two',upper='four'), s.clip(lower='four',upper='two')], axis=1)
Код: Выделить всё
0 1
0 four four
1 four four
2 four four
3 two two
4 two two
5 two two
6 two two
P.S. Отчет об ошибке на GitHub: https://github.com/pandas-dev/pandas/issues/49217
Подробнее здесь: https://stackoverflow.com/questions/741 ... ong-result