【发布时间】:2021-08-14 07:28:51
【问题描述】:
我必须' \\n, *, ' ==> '\n *'
但我尝试使用
df['Course_content']=df['Course_content'].replace(' \\n, *, ','\n *',regex=True)
但它不适合我
>>> df['Course_content'][0]
'The syllabus for this course will cover the following:, \\n, *, The nature and purpose of cost and management accounting, \\n, *, Source documents and coding, \\n, *, Cost classification and measuring, \\n, *, Recording costs, \\n, *, Spreadsheets'
>>> df['Course_content']=df['Course_content'].replace(' \\n, *, ','\n *',regex=True)
>>> df['Course_content'][0]
'The syllabus for this course will cover the following:, \\n, *, The nature and purpose of cost and management accounting, \\n, *, Source documents and coding, \\n, *, Cost classification and measuring, \\n, *, Recording costs, \\n, *, Spreadsheets'
>>>
我也尝试使用以下代码,但它也不适合我
d = {
'Not Mentioned':'',
"\r\n": "\n",
"\\r": "\n",
'\u00a0':' ',
' \\n, *,': "\n * ",
' \\n,':'\n',
}
df=df.replace(d.keys(),d.values(),regex=True)
【问题讨论】:
标签: python regex pandas dataframe data-cleaning