質問編集履歴

2

エラーコートを修正しました

2023/01/24 14:34

投稿

daisuke0925
daisuke0925

スコア5

test CHANGED
File without changes
test CHANGED
@@ -18,58 +18,69 @@
18
18
 
19
19
  [4 rows x 2914 columns]
20
20
 
21
- print(df.mean()["Q5.1,Q1,1"])
22
- と入力したら
23
- C:\Users\Owner\AppData\Local\Temp\ipykernel_11160\3464121936.py:1: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid columns before calling the reduction.
24
- print(df.mean()["Q5.1,Q1,1"])
25
- KeyError Traceback (most recent call last)
26
- File ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3621, in Index.get_loc(self, key, method, tolerance)
27
- 3620 try:
28
- -> 3621 return self._engine.get_loc(casted_key)
29
- 3622 except KeyError as err:
21
+ df.iloc[1:].mean()[['Q5.1','Q1']]
22
+ と入力してみると
30
23
 
31
- File ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx:136, in pandas._libs.index.IndexEngine.get_loc()
32
-
33
- File ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx:163, in pandas._libs.index.IndexEngine.get_loc()
34
-
35
- File pandas\_libs\hashtable_class_helper.pxi:5198, in pandas._libs.hashtable.PyObjectHashTable.get_item()
36
-
37
- File pandas\_libs\hashtable_class_helper.pxi:5206, in pandas._libs.hashtable.PyObjectHashTable.get_item()
38
-
39
- KeyError: 'Q5.1,Q1,1'
40
-
41
- The above exception was the direct cause of the following exception:
24
+ C:\Users\Owner\AppData\Local\Temp\ipykernel_2652\3443647166.py:1: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid columns before calling the reduction.
25
+ df.iloc[1:].mean()[['Q5.1','Q1']]
42
26
 
43
27
  KeyError Traceback (most recent call last)
44
- Input In [33], in <cell line: 1>()
28
+ Input In [12], in <cell line: 1>()
45
- ----> 1 print(df.mean()["Q5.1,Q1,1"])
29
+ ----> 1 df.iloc[1:].mean()[['Q5.1','Q1']]
46
30
 
47
- File ~\anaconda3\lib\site-packages\pandas\core\series.py:958, in Series.__getitem__(self, key)
31
+ File ~\anaconda3\lib\site-packages\pandas\core\series.py:984, in Series.__getitem__(self, key)
32
+ 981 key = np.asarray(key, dtype=bool)
48
- 955 return self._values[key]
33
+ 982 return self._get_values(key)
49
- 957 elif key_is_scalar:
50
- --> 958 return self._get_value(key)
34
+ --> 984 return self._get_with(key)
51
- 960 if is_hashable(key):
52
- 961 # Otherwise index.get_value will raise InvalidIndexError
53
- 962 try:
54
- 963 # For labels that don't resolve as scalars like tuples and frozensets
55
35
 
56
- File ~\anaconda3\lib\site-packages\pandas\core\series.py:1069, in Series._get_value(self, label, takeable)
36
+ File ~\anaconda3\lib\site-packages\pandas\core\series.py:1024, in Series._get_with(self, key)
57
- 1066 return self._values[label]
37
+ 1021 return self.iloc[key]
58
- 1068 # Similar to Index.get_value, but we do not fall back to positional
38
+ 1023 # handle the dup indexing case GH#4246
59
- -> 1069 loc = self.index.get_loc(label)
39
+ -> 1024 return self.loc[key]
60
- 1070 return self.index._get_values_for_loc(self, loc, label)
61
40
 
62
- File ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3623, in Index.get_loc(self, key, method, tolerance)
41
+ File ~\anaconda3\lib\site-packages\pandas\core\indexing.py:967, in _LocationIndexer.__getitem__(self, key)
63
- 3621 return self._engine.get_loc(casted_key)
64
- 3622 except KeyError as err:
42
+ 964 axis = self.axis or 0
65
- -> 3623 raise KeyError(key) from err
66
- 3624 except TypeError:
67
- 3625 # If we have a listlike key, _check_indexing_error will raise
43
+ 966 maybe_callable = com.apply_if_callable(key, self.obj)
68
- 3626 # InvalidIndexError. Otherwise we fall through and re-raise
44
+ --> 967 return self._getitem_axis(maybe_callable, axis=axis)
69
- 3627 # the TypeError.
70
- 3628 self._check_indexing_error(key)
71
45
 
46
+ File ~\anaconda3\lib\site-packages\pandas\core\indexing.py:1191, in _LocIndexer._getitem_axis(self, key, axis)
47
+ 1188 if hasattr(key, "ndim") and key.ndim > 1:
48
+ 1189 raise ValueError("Cannot index with multidimensional key")
49
+ -> 1191 return self._getitem_iterable(key, axis=axis)
50
+ 1193 # nested tuple slicing
51
+ 1194 if is_nested_tuple(key, labels):
52
+
53
+ File ~\anaconda3\lib\site-packages\pandas\core\indexing.py:1132, in _LocIndexer._getitem_iterable(self, key, axis)
54
+ 1129 self._validate_key(key, axis)
55
+ 1131 # A collection of keys
56
+ -> 1132 keyarr, indexer = self._get_listlike_indexer(key, axis)
57
+ 1133 return self.obj._reindex_with_indexers(
58
+ 1134 {axis: [keyarr, indexer]}, copy=True, allow_dups=True
59
+ 1135 )
60
+
61
+ File ~\anaconda3\lib\site-packages\pandas\core\indexing.py:1327, in _LocIndexer._get_listlike_indexer(self, key, axis)
62
+ 1324 ax = self.obj._get_axis(axis)
63
+ 1325 axis_name = self.obj._get_axis_name(axis)
64
+ -> 1327 keyarr, indexer = ax._get_indexer_strict(key, axis_name)
65
+ 1329 return keyarr, indexer
66
+
67
+ File ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:5782, in Index._get_indexer_strict(self, key, axis_name)
68
+ 5779 else:
69
+ 5780 keyarr, indexer, new_indexer = self._reindex_non_unique(keyarr)
70
+ -> 5782 self._raise_if_missing(keyarr, indexer, axis_name)
72
- KeyError: 'Q5.1,Q1,1'
71
+ 5784 keyarr = self.take(indexer)
72
+ 5785 if isinstance(key, Index):
73
+ 5786 # GH 42790 - Preserve name from an Index
74
+
75
+ File ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:5842, in Index._raise_if_missing(self, key, indexer, axis_name)
76
+ 5840 if use_interval_msg:
77
+ 5841 key = list(key)
78
+ -> 5842 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
79
+ 5844 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
80
+ 5845 raise KeyError(f"{not_found} not in index")
81
+
82
+ KeyError: "None of [Index(['Q5.1', 'Q1'], dtype='object')] are in the [index]"
83
+
73
- と表示されてしまうのですが、男女別の身長と体重の記述統計をどう求めればよろしいのでしょうか
84
+ と表示されてしまうのですが、どう対応すればよいのかを教えていただきたい
74
85
  (データのQ1は性別で、1は男性、2は女性、Q5.1は身長です)
75
86
 

1

タイトル

2023/01/23 23:48

投稿

daisuke0925
daisuke0925

スコア5

test CHANGED
@@ -1 +1 @@
1
- データを用いて記述統計を計算したい
1
+ Python データを用いて記述統計を計算したい
test CHANGED
File without changes