0

我正在尝试在数据框中格式化参考书目。基本上,对于名为“参考书目”的列,我想提取标题,有时由有时用“

现在当我使用

df.loc[df['Bibliography'].str.extract(?<=&quot;)(.*?)(?=,&quot;)

它正确提取由 " 分隔的标题(但会为由 分隔的标题生成 NaN)

所以我尝试使用 .loc 在数据帧的切片上应用 str.extract

df.loc[df['Bibliography'].str.contains('&quot;'),'Bibliography']=df.loc[df['Bibliography'].str.contains('&quot;'),'Bibliography'].str.extract(r'(?<=&quot;)(.*?)(?=,&quot;)')

但这会导致 NaN。我不知道为什么我不能在数据帧的一部分上使用提取。

4

0 回答 0