Как убрать смс-сообщения с данными, извлеченными с мобильного телефона.Я хочу сделать это с Python-Pandas.Мне нужно очистить данные из SMS-сообщений, и я хочу извлечь тело сообщения и исключить квадратные скобки.
Example of sms message is:
' <sms protocol="0" address="+14242380303" date="1407256816998" type="1" subject="null" body="ChatON : 3630 Message is sent from the ChatON service." toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="5. kol 2014. 06:40:16 PM" contact_name="(Unknown)" />'
Я использую этот код для извлечения тела сообщения.
func = lambda x: re.findall('(?<=\[)[^]]+(?=\])', x)
df=df.applymap(func)
Это DataFrame с «столбцом тела», который я хочу очистить.
Text
2 [Ok]
3 [Ok]
4 [Ok]
5 [U sedam u Dramaru kafa]
6 [Ok]
And I get this error
TypeError Traceback (most recent call last)
<ipython-input-10-f8a330ca2fe3> in <module>
1 func = lambda x: re.findall('(?<=\[)[^]]+(?=\])', x)
----> 2 df=df.applymap(func)
3
4
~/.local/lib/python3.6/site-packages/pandas/core/frame.py in applymap(self, func)
6070 return lib.map_infer(x.astype(object).values, func)
6071
-> 6072 return self.apply(infer)
6073
6074 # ----------------------------------------------------------------------
~/.local/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
6012 args=args,
6013 kwds=kwds)
-> 6014 return op.get_result()
6015
6016 def applymap(self, func):
~/.local/lib/python3.6/site-packages/pandas/core/apply.py in get_result(self)
316 *self.args, **self.kwds)
317
--> 318 return super(FrameRowApply, self).get_result()
319
320 def apply_broadcast(self):
~/.local/lib/python3.6/site-packages/pandas/core/apply.py in get_result(self)
140 return self.apply_raw()
141
--> 142 return self.apply_standard()
143
144 def apply_empty_result(self):
~/.local/lib/python3.6/site-packages/pandas/core/apply.py in apply_standard(self)
246
247 # compute the result using the series generator
--> 248 self.apply_series_generator()
249
250 # wrap results
~/.local/lib/python3.6/site-packages/pandas/core/apply.py in apply_series_generator(self)
275 try:
276 for i, v in enumerate(series_gen):
--> 277 results[i] = self.f(v)
278 keys.append(v.name)
279 except Exception as e:
~/.local/lib/python3.6/site-packages/pandas/core/frame.py in infer(x)
6068 if x.empty:
6069 return lib.map_infer(x, func)
-> 6070 return lib.map_infer(x.astype(object).values, func)
6071
6072 return self.apply(infer)
pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-10-f8a330ca2fe3> in <lambda>(x)
----> 1 func = lambda x: re.findall('(?<=\[)[^]]+(?=\])', x)
2 df=df.applymap(func)
3
4
/usr/lib/python3.6/re.py in findall(pattern, string, flags)
220
221 Empty matches are included in the result."""
--> 222 return _compile(pattern, flags).findall(string)
223
224 def finditer(pattern, string, flags=0):
TypeError: ('expected string or bytes-like object', 'occurred at index Text')