teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

追記

2021/01/31 23:27

投稿

fukubaka
fukubaka

スコア11

title CHANGED
File without changes
body CHANGED
@@ -13,4 +13,100 @@
13
13
  '“', '★', '”', '–', '●', 'â', '►', '−', '¢', '²', '¬', '░', '¶', '↑', '±', '¿', '▾', '═', '¦', '║', '―', '¥', '▓', '—', '‹', '─', '\u3000', '\u202f',
14
14
  '▒', ':', '¼', '⊕', '▼', '▪', '†', '■', '’', '▀', '¨', '▄', '♫', '☆', 'é', '¯', '♦', '¤', '▲', 'è', '¸', '¾', 'Ã', '⋅', '‘', '∞', '«',
15
15
  '∙', ')', '↓', '、', '│', '(', '»', ',', '♪', '╩', '╚', '³', '・', '╦', '╣', '╔', '╗', '▬', '❤', 'ï', 'Ø', '¹', '≤', '‡', '√', ]
16
+ ```
17
+
18
+ ### 追記
19
+ 頂いた回答をもとに、次のように実行したところこのようなエラーが出ました。
20
+ position17というのは、punctsの17個目にエラーの原因があるということでしょうか?
21
+
22
+ ```python
23
+ puncts= r',|.|"|:|)|(|-|!|?|;|""|$|&|/|[|]|\>|%|=|#|*|+|\|•|~|@|£|·|_|{|}|©|^|®|`|<|→|°|€|™|›|♥|←|×|§|″|′|Â|█|½|à|…|\n|\xa0|\t|“|★|”|–|●|â|►|−|¢|²|¬|░|¶|↑|±|¿|▾|═|¦|║|―|¥|▓|—|‹|─|\u3000|\u202f|▒|:|¼|⊕|▼|▪|†|■|’|▀|¨|▄|♫|☆|é|¯|♦|¤|▲|è|¸|¾|Ã|⋅|‘|∞|«|∙|)|↓|、|│|(|»|||♪|╩|╚|³|・|╦|╣|╔|╗|▬|❤|ï|Ø|¹|≤|‡|√'
24
+
25
+ def puncts_rm(s):
26
+ return re.sub(puncts, '', s)
27
+
28
+ (省略)
29
+
30
+ df["title2"] = df["title2"].apply(puncts_rm)
31
+ print(df["title2"])
32
+ ```
33
+ ```
34
+ (省略)
35
+
36
+ 10 df["title2"] = df["title2"].apply(puncts_rm)
37
+ 11 print(df["title2"])
38
+
39
+ ~\anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
40
+ 3589 else:
41
+ 3590 values = self.astype(object).values
42
+ -> 3591 mapped = lib.map_infer(values, f, convert=convert_dtype)
43
+ 3592
44
+ 3593 if len(mapped) and isinstance(mapped[0], Series):
45
+
46
+ pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
47
+
48
+ <ipython-input-84-2b440d6a84a2> in puncts_rm(s)
49
+ 1 def puncts_rm(s):
50
+ ----> 2 return re.sub(puncts, '', s)
51
+ 3
52
+ 4 def html_tags_rm(s):
53
+ 5 return re.sub(html_tags, '', s)
54
+
55
+ ~\anaconda3\lib\re.py in sub(pattern, repl, string, count, flags)
56
+ 190 a callable, it's passed the Match object and must return
57
+ 191 a replacement string to be used."""
58
+ --> 192 return _compile(pattern, flags).sub(repl, string, count)
59
+ 193
60
+ 194 def subn(pattern, repl, string, count=0, flags=0):
61
+
62
+ ~\anaconda3\lib\re.py in _compile(pattern, flags)
63
+ 284 if not sre_compile.isstring(pattern):
64
+ 285 raise TypeError("first argument must be string or compiled pattern")
65
+ --> 286 p = sre_compile.compile(pattern, flags)
66
+ 287 if not (flags & DEBUG):
67
+ 288 if len(_cache) >= _MAXCACHE:
68
+
69
+ ~\anaconda3\lib\sre_compile.py in compile(p, flags)
70
+ 762 if isstring(p):
71
+ 763 pattern = p
72
+ --> 764 p = sre_parse.parse(p, flags)
73
+ 765 else:
74
+ 766 pattern = None
75
+
76
+ ~\anaconda3\lib\sre_parse.py in parse(str, flags, pattern)
77
+ 922
78
+ 923 try:
79
+ --> 924 p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
80
+ 925 except Verbose:
81
+ 926 # the VERBOSE flag was switched on inside the pattern. to be
82
+
83
+ ~\anaconda3\lib\sre_parse.py in _parse_sub(source, state, verbose, nested)
84
+ 418 while True:
85
+ 419 itemsappend(_parse(source, state, verbose, nested + 1,
86
+ --> 420 not nested and not items))
87
+ 421 if not sourcematch("|"):
88
+ 422 break
89
+
90
+ ~\anaconda3\lib\sre_parse.py in _parse(source, state, verbose, nested, first)
91
+ 808 sub_verbose = ((verbose or (add_flags & SRE_FLAG_VERBOSE)) and
92
+ 809 not (del_flags & SRE_FLAG_VERBOSE))
93
+ --> 810 p = _parse_sub(source, state, sub_verbose, nested + 1)
94
+ 811 if not source.match(")"):
95
+ 812 raise source.error("missing ), unterminated subpattern",
96
+
97
+ ~\anaconda3\lib\sre_parse.py in _parse_sub(source, state, verbose, nested)
98
+ 418 while True:
99
+ 419 itemsappend(_parse(source, state, verbose, nested + 1,
100
+ --> 420 not nested and not items))
101
+ 421 if not sourcematch("|"):
102
+ 422 break
103
+
104
+ ~\anaconda3\lib\sre_parse.py in _parse(source, state, verbose, nested, first)
105
+ 643 if not item or item[0][0] is AT:
106
+ 644 raise source.error("nothing to repeat",
107
+ --> 645 source.tell() - here + len(this))
108
+ 646 if item[0][0] in _REPEATCODES:
109
+ 647 raise source.error("multiple repeat",
110
+
111
+ error: nothing to repeat at position 17
16
112
  ```