1
パンダ0.18.1を使用すると、dtype
がcategory
のカラムをフィルタリングするときに違った動作が実現しました。ここには最小の例があります。整数型の列の値のいずれかをフィルタリングパンダ:カテゴリdtypeとフィルタ
import pandas as pd
import numpy as np
l = np.random.randint(1, 4, 50)
df = pd.DataFrame(dict(c_type=l, i_type=l))
df['c_type'] = df.c_type.astype('category')
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 50 entries, 0 to 49
Data columns (total 2 columns):
c_type 50 non-null category
i_type 50 non-null int64
dtypes: category(1), int64(1)
memory usage: 554.0 bytes
df[df.i_type.isin([1, 2])].i_type.value_counts()
2 20
1 17
Name: i_type, dtype: int64
につながるが、カテゴリタイプ列に同じフィルタリングエントリー
df[df.c_type.isin([1, 2])].c_type.value_counts()
2 20
1 17
3 0
Name: c_type, dtype: int64
ようにフィルタリングされた値を保持しますフィルタは動作しますが、動作は私にとっては珍しいようです。例えば、category
を扱うときに余分なフィルタを必要とするpivot_table
関数から将来の列を除外するためにフィルタを使用できます。
これは正常な動作ですか?
です。この点を強調していただきありがとうございます。 –