質問編集履歴
7
内容更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -115,3 +115,31 @@
|
|
115
115
|
KeyError: '装置名'
|
116
116
|
|
117
117
|
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
補足になります。
|
122
|
+
|
123
|
+
もとのDFは以下の形です。
|
124
|
+
|
125
|
+
これにpivotを使用したら上記の形のマルチインデックスになってしまいました。
|
126
|
+
|
127
|
+
|NO|データ取得日時|装置名|照度|---|---|---|
|
128
|
+
|
129
|
+
|:--:|:--:|:--:|:--:|:--:|:--:|
|
130
|
+
|
131
|
+
|0|2020-07-01| SEN02RM01|NaN|NaN|NaN|NaN|
|
132
|
+
|
133
|
+
|1|2020-07-01| SEN02RM55|NaN|NaN|NaN|NaN|
|
134
|
+
|
135
|
+
|---|---|---|---|---|---|---|
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
上記を以下コマンドで変換しました。
|
140
|
+
|
141
|
+
```pyton
|
142
|
+
|
143
|
+
df7 = pd.pivot_table(df7, index='データ取得日時', columns='装置名')
|
144
|
+
|
145
|
+
```
|
6
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
上記を以下のコマンドで、装置行の特定文字を含む列の抽出をしたいのですが、以下エラーが出ます。
|
19
|
+
上記を以下のコマンドで、「装置名」行の特定文字を含む列の抽出をしたいのですが、以下エラーが出ます。
|
20
20
|
|
21
21
|
なぜかわからないです。助けてください。宜しくお願いします。
|
22
22
|
|
5
エラー内容修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,133 +34,81 @@
|
|
34
34
|
|
35
35
|
```error
|
36
36
|
|
37
|
-
---------------------------------------------------------------------------
|
38
|
-
|
39
37
|
KeyError Traceback (most recent call last)
|
40
38
|
|
41
|
-
|
39
|
+
<ipython-input-46-31f3d6482c11> in <module>
|
42
40
|
|
43
|
-
2890 try:
|
44
|
-
|
45
|
-
->
|
41
|
+
----> 1 df7 = df7.loc['装置名'].str.contains('SEN01')
|
46
|
-
|
47
|
-
2892 except KeyError as err:
|
48
42
|
|
49
43
|
|
50
44
|
|
51
|
-
|
45
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexing.py in __getitem__(self, key)
|
46
|
+
|
47
|
+
877
|
48
|
+
|
49
|
+
878 maybe_callable = com.apply_if_callable(key, self.obj)
|
50
|
+
|
51
|
+
--> 879 return self._getitem_axis(maybe_callable, axis=axis)
|
52
|
+
|
53
|
+
880
|
54
|
+
|
55
|
+
881 def _is_scalar_access(self, key: Tuple):
|
52
56
|
|
53
57
|
|
54
58
|
|
59
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
|
60
|
+
|
61
|
+
1108 # fall thru to straight lookup
|
62
|
+
|
63
|
+
1109 self._validate_key(key, axis)
|
64
|
+
|
65
|
+
-> 1110 return self._get_label(key, axis=axis)
|
66
|
+
|
67
|
+
1111
|
68
|
+
|
55
|
-
|
69
|
+
1112 def _get_slice_axis(self, slice_obj: slice, axis: int):
|
56
70
|
|
57
71
|
|
58
72
|
|
59
|
-
|
73
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
|
74
|
+
|
75
|
+
1057 def _get_label(self, label, axis: int):
|
76
|
+
|
77
|
+
1058 # GH#5667 this will fail if the label is not present in the axis.
|
78
|
+
|
79
|
+
-> 1059 return self.obj.xs(label, axis=axis)
|
80
|
+
|
81
|
+
1060
|
82
|
+
|
83
|
+
1061 def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
|
60
84
|
|
61
85
|
|
62
86
|
|
63
|
-
|
87
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
|
88
|
+
|
89
|
+
3486 loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
|
90
|
+
|
91
|
+
3487 else:
|
92
|
+
|
93
|
+
-> 3488 loc = self.index.get_loc(key)
|
94
|
+
|
95
|
+
3489
|
96
|
+
|
97
|
+
3490 if isinstance(loc, np.ndarray):
|
64
98
|
|
65
99
|
|
66
100
|
|
67
|
-
|
101
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance)
|
68
102
|
|
103
|
+
356 except ValueError as err:
|
69
104
|
|
105
|
+
357 raise KeyError(key) from err
|
70
106
|
|
71
|
-
|
107
|
+
--> 358 raise KeyError(key)
|
72
108
|
|
109
|
+
359 return super().get_loc(key, method=method, tolerance=tolerance)
|
73
110
|
|
74
|
-
|
75
|
-
KeyError Traceback (most recent call last)
|
76
|
-
|
77
|
-
<ipython-input-45-1723b5723330> in <module>
|
78
|
-
|
79
|
-
----> 1 df7 = df7['装置名'].str.contains('SEN01')
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
|
84
|
-
|
85
|
-
2899 if is_single_key:
|
86
|
-
|
87
|
-
2900 if self.columns.nlevels > 1:
|
88
|
-
|
89
|
-
-> 2901 return self._getitem_multilevel(key)
|
90
|
-
|
91
|
-
2902 indexer = self.columns.get_loc(key)
|
92
|
-
|
93
|
-
2903 if is_integer(indexer):
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/frame.py in _getitem_multilevel(self, key)
|
98
|
-
|
99
|
-
2949 def _getitem_multilevel(self, key):
|
100
|
-
|
101
|
-
2950 # self.columns is a MultiIndex
|
102
|
-
|
103
|
-
-> 2951 loc = self.columns.get_loc(key)
|
104
|
-
|
105
|
-
2952 if isinstance(loc, (slice, np.ndarray)):
|
106
|
-
|
107
|
-
2953 new_columns = self.columns[loc]
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/multi.py in get_loc(self, key, method)
|
112
|
-
|
113
|
-
|
111
|
+
360
|
114
|
-
|
115
|
-
2700 if not isinstance(key, tuple):
|
116
|
-
|
117
|
-
-> 2701 loc = self._get_level_indexer(key, level=0)
|
118
|
-
|
119
|
-
2702 return _maybe_to_slice(loc)
|
120
|
-
|
121
|
-
2703
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/multi.py in _get_level_indexer(self, key, level, indexer)
|
126
|
-
|
127
|
-
2964 else:
|
128
|
-
|
129
|
-
2965
|
130
|
-
|
131
|
-
-> 2966 code = self._get_loc_single_level_index(level_index, key)
|
132
|
-
|
133
|
-
2967
|
134
|
-
|
135
|
-
2968 if level > 0 or self.lexsort_depth == 0:
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/multi.py in _get_loc_single_level_index(self, level_index, key)
|
140
|
-
|
141
|
-
2632 return -1
|
142
|
-
|
143
|
-
2633 else:
|
144
|
-
|
145
|
-
-> 2634 return level_index.get_loc(key)
|
146
|
-
|
147
|
-
2635
|
148
|
-
|
149
|
-
2636 def get_loc(self, key, method=None):
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
|
154
|
-
|
155
|
-
2891 return self._engine.get_loc(casted_key)
|
156
|
-
|
157
|
-
2892 except KeyError as err:
|
158
|
-
|
159
|
-
-> 2893 raise KeyError(key) from err
|
160
|
-
|
161
|
-
2894
|
162
|
-
|
163
|
-
2895 if tolerance is not None:
|
164
112
|
|
165
113
|
|
166
114
|
|
4
内容修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
```python
|
26
26
|
|
27
|
-
df7 = df7['装置名'].str.contains('SEN01')
|
27
|
+
df7 = df7.loc['装置名'].str.contains('SEN01')
|
28
28
|
|
29
29
|
```
|
30
30
|
|
3
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
以下のようなマルチインデックスのDF7があります。
|
2
2
|
|
3
|
-
実際は列数はもっとあります。
|
3
|
+
実際は列行数はもっとあります。
|
4
4
|
|
5
5
|
|
6
6
|
|
2
誤字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
以下のようなマルチインデックスのDFがあります。
|
1
|
+
以下のようなマルチインデックスのDF7があります。
|
2
2
|
|
3
3
|
実際は列数はもっとあります。
|
4
4
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
```python
|
26
26
|
|
27
|
-
df7 = df['装置名'].str.contains('SEN01')
|
27
|
+
df7 = df7['装置名'].str.contains('SEN01')
|
28
28
|
|
29
29
|
```
|
30
30
|
|
1
エラー追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,143 @@
|
|
27
27
|
df7 = df['装置名'].str.contains('SEN01')
|
28
28
|
|
29
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
エラー内容以下
|
34
|
+
|
35
|
+
```error
|
36
|
+
|
37
|
+
---------------------------------------------------------------------------
|
38
|
+
|
39
|
+
KeyError Traceback (most recent call last)
|
40
|
+
|
41
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
|
42
|
+
|
43
|
+
2890 try:
|
44
|
+
|
45
|
+
-> 2891 return self._engine.get_loc(casted_key)
|
46
|
+
|
47
|
+
2892 except KeyError as err:
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
KeyError: '装置名'
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
The above exception was the direct cause of the following exception:
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
KeyError Traceback (most recent call last)
|
76
|
+
|
77
|
+
<ipython-input-45-1723b5723330> in <module>
|
78
|
+
|
79
|
+
----> 1 df7 = df7['装置名'].str.contains('SEN01')
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
|
84
|
+
|
85
|
+
2899 if is_single_key:
|
86
|
+
|
87
|
+
2900 if self.columns.nlevels > 1:
|
88
|
+
|
89
|
+
-> 2901 return self._getitem_multilevel(key)
|
90
|
+
|
91
|
+
2902 indexer = self.columns.get_loc(key)
|
92
|
+
|
93
|
+
2903 if is_integer(indexer):
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/frame.py in _getitem_multilevel(self, key)
|
98
|
+
|
99
|
+
2949 def _getitem_multilevel(self, key):
|
100
|
+
|
101
|
+
2950 # self.columns is a MultiIndex
|
102
|
+
|
103
|
+
-> 2951 loc = self.columns.get_loc(key)
|
104
|
+
|
105
|
+
2952 if isinstance(loc, (slice, np.ndarray)):
|
106
|
+
|
107
|
+
2953 new_columns = self.columns[loc]
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/multi.py in get_loc(self, key, method)
|
112
|
+
|
113
|
+
2699
|
114
|
+
|
115
|
+
2700 if not isinstance(key, tuple):
|
116
|
+
|
117
|
+
-> 2701 loc = self._get_level_indexer(key, level=0)
|
118
|
+
|
119
|
+
2702 return _maybe_to_slice(loc)
|
120
|
+
|
121
|
+
2703
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/multi.py in _get_level_indexer(self, key, level, indexer)
|
126
|
+
|
127
|
+
2964 else:
|
128
|
+
|
129
|
+
2965
|
130
|
+
|
131
|
+
-> 2966 code = self._get_loc_single_level_index(level_index, key)
|
132
|
+
|
133
|
+
2967
|
134
|
+
|
135
|
+
2968 if level > 0 or self.lexsort_depth == 0:
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/multi.py in _get_loc_single_level_index(self, level_index, key)
|
140
|
+
|
141
|
+
2632 return -1
|
142
|
+
|
143
|
+
2633 else:
|
144
|
+
|
145
|
+
-> 2634 return level_index.get_loc(key)
|
146
|
+
|
147
|
+
2635
|
148
|
+
|
149
|
+
2636 def get_loc(self, key, method=None):
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
~/todakensetu_analytics/.venv/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
|
154
|
+
|
155
|
+
2891 return self._engine.get_loc(casted_key)
|
156
|
+
|
157
|
+
2892 except KeyError as err:
|
158
|
+
|
159
|
+
-> 2893 raise KeyError(key) from err
|
160
|
+
|
161
|
+
2894
|
162
|
+
|
163
|
+
2895 if tolerance is not None:
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
KeyError: '装置名'
|
168
|
+
|
169
|
+
```
|