質問編集履歴

1

追記

2021/01/31 23:27

投稿

fukubaka
fukubaka

スコア11

test CHANGED
File without changes
test CHANGED
@@ -29,3 +29,195 @@
29
29
  '∙', ')', '↓', '、', '│', '(', '»', ',', '♪', '╩', '╚', '³', '・', '╦', '╣', '╔', '╗', '▬', '❤', 'ï', 'Ø', '¹', '≤', '‡', '√', ]
30
30
 
31
31
  ```
32
+
33
+
34
+
35
+ ### 追記
36
+
37
+ 頂いた回答をもとに、次のように実行したところこのようなエラーが出ました。
38
+
39
+ position17というのは、punctsの17個目にエラーの原因があるということでしょうか?
40
+
41
+
42
+
43
+ ```python
44
+
45
+ puncts= r',|.|"|:|)|(|-|!|?|;|""|$|&|/|[|]|\>|%|=|#|*|+|\|•|~|@|£|·|_|{|}|©|^|®|`|<|→|°|€|™|›|♥|←|×|§|″|′|Â|█|½|à|…|\n|\xa0|\t|“|★|”|–|●|â|►|−|¢|²|¬|░|¶|↑|±|¿|▾|═|¦|║|―|¥|▓|—|‹|─|\u3000|\u202f|▒|:|¼|⊕|▼|▪|†|■|’|▀|¨|▄|♫|☆|é|¯|♦|¤|▲|è|¸|¾|Ã|⋅|‘|∞|«|∙|)|↓|、|│|(|»|||♪|╩|╚|³|・|╦|╣|╔|╗|▬|❤|ï|Ø|¹|≤|‡|√'
46
+
47
+
48
+
49
+ def puncts_rm(s):
50
+
51
+ return re.sub(puncts, '', s)
52
+
53
+
54
+
55
+ (省略)
56
+
57
+
58
+
59
+ df["title2"] = df["title2"].apply(puncts_rm)
60
+
61
+ print(df["title2"])
62
+
63
+ ```
64
+
65
+ ```
66
+
67
+ (省略)
68
+
69
+
70
+
71
+ 10 df["title2"] = df["title2"].apply(puncts_rm)
72
+
73
+ 11 print(df["title2"])
74
+
75
+
76
+
77
+ ~\anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
78
+
79
+ 3589 else:
80
+
81
+ 3590 values = self.astype(object).values
82
+
83
+ -> 3591 mapped = lib.map_infer(values, f, convert=convert_dtype)
84
+
85
+ 3592
86
+
87
+ 3593 if len(mapped) and isinstance(mapped[0], Series):
88
+
89
+
90
+
91
+ pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
92
+
93
+
94
+
95
+ <ipython-input-84-2b440d6a84a2> in puncts_rm(s)
96
+
97
+ 1 def puncts_rm(s):
98
+
99
+ ----> 2 return re.sub(puncts, '', s)
100
+
101
+ 3
102
+
103
+ 4 def html_tags_rm(s):
104
+
105
+ 5 return re.sub(html_tags, '', s)
106
+
107
+
108
+
109
+ ~\anaconda3\lib\re.py in sub(pattern, repl, string, count, flags)
110
+
111
+ 190 a callable, it's passed the Match object and must return
112
+
113
+ 191 a replacement string to be used."""
114
+
115
+ --> 192 return _compile(pattern, flags).sub(repl, string, count)
116
+
117
+ 193
118
+
119
+ 194 def subn(pattern, repl, string, count=0, flags=0):
120
+
121
+
122
+
123
+ ~\anaconda3\lib\re.py in _compile(pattern, flags)
124
+
125
+ 284 if not sre_compile.isstring(pattern):
126
+
127
+ 285 raise TypeError("first argument must be string or compiled pattern")
128
+
129
+ --> 286 p = sre_compile.compile(pattern, flags)
130
+
131
+ 287 if not (flags & DEBUG):
132
+
133
+ 288 if len(_cache) >= _MAXCACHE:
134
+
135
+
136
+
137
+ ~\anaconda3\lib\sre_compile.py in compile(p, flags)
138
+
139
+ 762 if isstring(p):
140
+
141
+ 763 pattern = p
142
+
143
+ --> 764 p = sre_parse.parse(p, flags)
144
+
145
+ 765 else:
146
+
147
+ 766 pattern = None
148
+
149
+
150
+
151
+ ~\anaconda3\lib\sre_parse.py in parse(str, flags, pattern)
152
+
153
+ 922
154
+
155
+ 923 try:
156
+
157
+ --> 924 p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
158
+
159
+ 925 except Verbose:
160
+
161
+ 926 # the VERBOSE flag was switched on inside the pattern. to be
162
+
163
+
164
+
165
+ ~\anaconda3\lib\sre_parse.py in _parse_sub(source, state, verbose, nested)
166
+
167
+ 418 while True:
168
+
169
+ 419 itemsappend(_parse(source, state, verbose, nested + 1,
170
+
171
+ --> 420 not nested and not items))
172
+
173
+ 421 if not sourcematch("|"):
174
+
175
+ 422 break
176
+
177
+
178
+
179
+ ~\anaconda3\lib\sre_parse.py in _parse(source, state, verbose, nested, first)
180
+
181
+ 808 sub_verbose = ((verbose or (add_flags & SRE_FLAG_VERBOSE)) and
182
+
183
+ 809 not (del_flags & SRE_FLAG_VERBOSE))
184
+
185
+ --> 810 p = _parse_sub(source, state, sub_verbose, nested + 1)
186
+
187
+ 811 if not source.match(")"):
188
+
189
+ 812 raise source.error("missing ), unterminated subpattern",
190
+
191
+
192
+
193
+ ~\anaconda3\lib\sre_parse.py in _parse_sub(source, state, verbose, nested)
194
+
195
+ 418 while True:
196
+
197
+ 419 itemsappend(_parse(source, state, verbose, nested + 1,
198
+
199
+ --> 420 not nested and not items))
200
+
201
+ 421 if not sourcematch("|"):
202
+
203
+ 422 break
204
+
205
+
206
+
207
+ ~\anaconda3\lib\sre_parse.py in _parse(source, state, verbose, nested, first)
208
+
209
+ 643 if not item or item[0][0] is AT:
210
+
211
+ 644 raise source.error("nothing to repeat",
212
+
213
+ --> 645 source.tell() - here + len(this))
214
+
215
+ 646 if item[0][0] in _REPEATCODES:
216
+
217
+ 647 raise source.error("multiple repeat",
218
+
219
+
220
+
221
+ error: nothing to repeat at position 17
222
+
223
+ ```