【发布时间】:2020-04-26 20:13:11
【问题描述】:
我想简化我的 3 行代码,将方括号去掉为一行:
df = pd.DataFrame(dict(words=['[hello]',
'[hello,[Name, World, Max]',
np.nan,
'[Goodbye]',
np.nan,
'[hello, [goodbye], hello]']))
df['words'].fillna("N/A", inplace=True)
df['words']=df['words'].str.extract("\[", "")
df['words']=df['words'].str.replace("\]", "")
我尝试了这里提到的几种方法,但都不起作用(替换、扩展):remove characters from pandas column
【问题讨论】: