実現したいこと
aggメソッドを利用して、"sex"と"address"について"age"と"G1"のカウント、平均、最大、最小を計算したい。
発生している問題・分からないこと
計算結果が表示されない。
エラーメッセージ
error
1ValueError Traceback (most recent call last) 2Cell In[110], line 5 3 3 functions = ["count","mean","max","min"] 4 4 grouped_student_math_data1 = student_data_math.groupby(["sex","address"]) 5----> 5 grouped_student_math_data1["age","G1"].agg(functions) 6 7File ~\anaconda3\Lib\site-packages\pandas\core\groupby\generic.py:1947, in DataFrameGroupBy.__getitem__(self, key) 8 1943 # per GH 23566 9 1944 if isinstance(key, tuple) and len(key) > 1: 10 1945 # if len == 1, then it becomes a SeriesGroupBy and this is actually 11 1946 # valid syntax, so don't raise 12-> 1947 raise ValueError( 13 1948 "Cannot subset columns with a tuple with more than one element. " 14 1949 "Use a list instead." 15 1950 ) 16 1951 return super().__getitem__(key) 17 18ValueError: Cannot subset columns with a tuple with more than one element. Use a list instead.
該当のソースコード
student_data_math = pd.read_csv("student-mat.csv", sep = ";") functions = ["count","mean","max","min"] grouped_student_math_data1 = student_data_math.groupby(["sex","address"]) grouped_student_math_data1["age","G1"].agg(functions)
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
自分なりにバージョンなど確認してみましたがわかりませんでした。
補足
特になし