<Python, pandas> Row/Columnの対で値を摘まむ
Row``と``Column
の対のセットで、値を選択する。
.lookup()
を使う。
In [42]: import seaborn as sns In [43]: df = sns.load_dataset('tips') In [44]: df.head() Out[44]: total_bill tip sex smoker day time size 0 16.99 1.01 Female No Sun Dinner 2 1 10.34 1.66 Male No Sun Dinner 3 2 21.01 3.50 Male No Sun Dinner 3 3 23.68 3.31 Male No Sun Dinner 2 4 24.59 3.61 Female No Sun Dinner 4
で、
In [50]: df.lookup([1,3],['tip','sex']) Out[50]: array([1.6599999999999999, 'Male'], dtype=object) In [51]: df.lookup([1,3,2,1,5],['tip','sex','day','day','size']) Out[51]: array([1.6599999999999999, 'Male', 'Sun', 'Sun', 4], dtype=object)
ふーん。