私はあなたがこれを行うには2つの方法があることがわかります。
全体データフレームについて
この方法は、全体のデータフレームにまれに生じる値を除去します。私たちはループを使わずに、組み込み関数を使って処理を高速化できます。
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0, high=9, size=(100,2)),
columns = ['A', 'B'])
threshold = 10 # Anything that occurs less than this will be removed.
value_counts = df.stack().value_counts() # Entire DataFrame
to_remove = value_counts[value_counts <= threshold].index
df.replace(to_remove, np.nan, inplace=True)
列ごと
この方法は、各列にまれに発生するエントリを削除します。
import pandas as np
import numpy as np
df = pd.DataFrame(np.random.randint(0, high=9, size=(100,2)),
columns = ['A', 'B'])
threshold = 10 # Anything that occurs less than this will be removed.
for col in df.columns:
value_counts = df[col].value_counts() # Specific column
to_remove = value_counts[value_counts <= threshold].index
df[col].replace(to_remove, np.nan, inplace=True)
"まれに会う"とはどういう意味ですか?あなたはもっと具体的になりますか?すでに試したコードを追加すると役立ちます。 – guaka
どのように「より具体的」なのか理解できませんか? '' '0'''のような' '' col_1'''値には '' '189096'''時間があります。そして '' '1569''のような価値は1回会う。私は '' '' col_1'''で '' '1569''と他の値を削除したいです。 –
Aha!あなたは「出会う」という意味ではなく、「出会う」という意味です。 – guaka