我在Python 3.5.1上使用pandas库。如何从字段值中删除html标记?这是我的输入和输出:
我的代码返回了错误:
import pandas as pd
code=[1,2,3]
overview =['<p>Environments subject.</p>',
'<ul><li> property ;</li></ul><ul><li>markets and exchange;</li></ul>',
'<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">']
# '<p class="SSPBodyText" style="padding: 0cm; text-align: justify;">The subject.</p>']
df= pd.DataFrame(overview,code)
df.columns = ['overview']
df['overview_copy'] = df['overview']
# print(df)
tags_list = ['<p>' ,'</p>' , '<p*>',
'<ul>','</ul>',
'<li>','</li>',
'<br>',
'<strong>','</strong>',
'<span*>','</span>',
'<a href*>','</a>',
'<em>','</em>']
for tag in tags_list:
# df['overview_copy'] = df['overview_copy'].str.replace(tag, '')
df['overview_copy'].replace(to_replace=tag, value='', regex=True, inplace=True)
print(df)