質問編集履歴
2
試したことに追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,9 +14,29 @@
|
|
14
14
|
|
15
15
|
3 2020/3/15 2020/4/8 2020/5/2 2020/5/8
|
16
16
|
|
17
|
+
|
18
|
+
|
19
|
+
"qpr1"は
|
20
|
+
|
21
|
+
性別 年齢 日時 ・・・
|
22
|
+
|
23
|
+
1 1 24 2020/4/18
|
24
|
+
|
25
|
+
2 0 39 2020/5/7
|
26
|
+
|
27
|
+
3 0 28 2020/4/24
|
28
|
+
|
29
|
+
・・・
|
30
|
+
|
17
31
|
のようになっています。
|
18
32
|
|
33
|
+
|
34
|
+
|
35
|
+
"期間"ファイルの'コード'1の行の'開始日1'と'終了日2'の期間内に、"qpr1"の'日時'が含まれていれば変数1を与えたいです。
|
36
|
+
|
19
|
-
|
37
|
+
"qpr1"の1,2,3...とすべてのデータに対して"期間"の'コード'1を対応させたいです。
|
38
|
+
|
39
|
+
|
20
40
|
|
21
41
|
### 発生している問題・エラーメッセージ
|
22
42
|
|
@@ -94,9 +114,139 @@
|
|
94
114
|
|
95
115
|
|
96
116
|
|
97
|
-
|
117
|
+
追加で試してみましたがまたエラーが発生してしまいました。
|
118
|
+
|
98
|
-
|
119
|
+
```python
|
120
|
+
|
99
|
-
|
121
|
+
コード
|
122
|
+
|
123
|
+
kyuko = pd.read_csv("期間.csv",encoding = "cp932")
|
124
|
+
|
125
|
+
qpr1 = pd.read_csv("qpr1.csv")
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
kyuko["開始日1"] = pd.to_datetime(kyuko["開始日1"])
|
130
|
+
|
131
|
+
kyuko["終了日2"] = pd.to_datetime(kyuko["終了日2"])
|
132
|
+
|
133
|
+
qpr1["日時"] = pd.to_datetime(qpr1["日時"])
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
qpr1[(qpr1["日時"] >= kyuko.loc[1,"開始日1"]) & (qpr1["日時"] <= kyuko.loc[1,"終了日2"]), "日時ダミー"] = 1
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
```python
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
エラーコード
|
148
|
+
|
149
|
+
TypeError Traceback (most recent call last)
|
150
|
+
|
151
|
+
<ipython-input-51-e0a8aafa4b96> in <module>
|
152
|
+
|
153
|
+
6 qpr["日時"] = pd.to_datetime(qpr1["日時"])
|
154
|
+
|
155
|
+
7
|
156
|
+
|
157
|
+
----> 8 qpr1[(qpr1["日時"] >= kyuko.loc[1,"開始日1"]) & (qpr1["日時"] <= kyuko.loc[1,"終了日2"]), "日時ダミー"] = 1
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
~\Anaconda3\lib\site-packages\pandas\core\frame.py in __setitem__(self, key, value)
|
162
|
+
|
163
|
+
2936 else:
|
164
|
+
|
165
|
+
2937 # set column
|
166
|
+
|
167
|
+
-> 2938 self._set_item(key, value)
|
168
|
+
|
169
|
+
2939
|
170
|
+
|
171
|
+
2940 def _setitem_slice(self, key, value):
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
~\Anaconda3\lib\site-packages\pandas\core\frame.py in _set_item(self, key, value)
|
176
|
+
|
177
|
+
2998
|
178
|
+
|
179
|
+
2999 self._ensure_valid_index(value)
|
180
|
+
|
181
|
+
-> 3000 value = self._sanitize_column(key, value)
|
182
|
+
|
183
|
+
3001 NDFrame._set_item(self, key, value)
|
184
|
+
|
185
|
+
3002
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
~\Anaconda3\lib\site-packages\pandas\core\frame.py in _sanitize_column(self, key, value, broadcast)
|
190
|
+
|
191
|
+
3664
|
192
|
+
|
193
|
+
3665 # broadcast across multiple columns if necessary
|
194
|
+
|
195
|
+
-> 3666 if broadcast and key in self.columns and value.ndim == 1:
|
196
|
+
|
197
|
+
3667 if not self.columns.is_unique or isinstance(self.columns, ABCMultiIndex):
|
198
|
+
|
199
|
+
3668 existing_piece = self[key]
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in __contains__(self, key)
|
204
|
+
|
205
|
+
3898 @Appender(_index_shared_docs["contains"] % _index_doc_kwargs)
|
206
|
+
|
207
|
+
3899 def __contains__(self, key) -> bool:
|
208
|
+
|
209
|
+
-> 3900 hash(key)
|
210
|
+
|
211
|
+
3901 try:
|
212
|
+
|
213
|
+
3902 return key in self._engine
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __hash__(self)
|
218
|
+
|
219
|
+
1796
|
220
|
+
|
221
|
+
1797 def __hash__(self):
|
222
|
+
|
223
|
+
-> 1798 raise TypeError(
|
224
|
+
|
225
|
+
1799 f"{repr(type(self).__name__)} objects are mutable, "
|
226
|
+
|
227
|
+
1800 f"thus they cannot be hashed"
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
TypeError: 'Series' objects are mutable, thus they cannot be hashed
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
```
|
100
250
|
|
101
251
|
### 補足情報(FW/ツールのバージョンなど)
|
102
252
|
|
1
エラーメッセージを編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,6 +21,52 @@
|
|
21
21
|
### 発生している問題・エラーメッセージ
|
22
22
|
|
23
23
|
```python
|
24
|
+
|
25
|
+
TypeError Traceback (most recent call last)
|
26
|
+
|
27
|
+
<ipython-input-20-c5c479f15b53> in <module>
|
28
|
+
|
29
|
+
1 kyuko = pd.read_csv("期間.csv",encoding="cp932")
|
30
|
+
|
31
|
+
----> 2 qpr1.loc[kyuko["1",["開始日1"]] <= qpr1["日時"] <= kyuko["1",["終了日2"]], "日時ダミー"] = 1
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
~\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
|
36
|
+
|
37
|
+
2798 if self.columns.nlevels > 1:
|
38
|
+
|
39
|
+
2799 return self._getitem_multilevel(key)
|
40
|
+
|
41
|
+
-> 2800 indexer = self.columns.get_loc(key)
|
42
|
+
|
43
|
+
2801 if is_integer(indexer):
|
44
|
+
|
45
|
+
2802 indexer = [indexer]
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
|
50
|
+
|
51
|
+
2644 )
|
52
|
+
|
53
|
+
2645 try:
|
54
|
+
|
55
|
+
-> 2646 return self._engine.get_loc(key)
|
56
|
+
|
57
|
+
2647 except KeyError:
|
58
|
+
|
59
|
+
2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
68
|
+
|
69
|
+
|
24
70
|
|
25
71
|
TypeError: '('1', ['開始日1'])' is an invalid key
|
26
72
|
|