パンダに次のデータフレームがあるとします。
import numpy as np
df = pandas.DataFrame({"a": np.random.random(100), "b": np.random.random(100), "id": np.arange(100)})
との値でid構成される各ポイントの ID はどこにありますか? 指定したビンのセットにとをビン化するにはどうすればよいですか (各ビンのとの中央値/平均値を取得できます)。の任意の行に対して、または(または両方) の値を持つ可能性があります。abababdfNaNabdf
ジョー・キングトンのソリューションをより現実的なdf. よくわからないのは、以下の各グループのdf.b要素にアクセスする方法です。df.a
a = np.random.random(20)
df = pandas.DataFrame({"a": a, "b": a + 10})
# bins for df.a
bins = np.linspace(0, 1, 10)
# bin df according to a
groups = df.groupby(np.digitize(df.a,bins))
# Get the mean of a in each group
print groups.mean()
## But how to get the mean of b for each group of a?
# ...