【发布时间】:2021-11-02 18:26:34
【问题描述】:
我的代码 -
df=pd.read_csv("file")
l1=[]
l2=[]
for i in range(0,len(df['unions']),len(df['district'])):
l1.append(' '.join((df['unions'][i], df['district'][i])))
l2.append(({"entities": [[(ele.start(), ele.end() - 1) for ele in re.finditer(r'\S+', df['unions'][i])] ,df['subdistrict'][i]],}))
TRAIN_DATA=list(zip(l1,l2))
print(TRAIN_DATA)
结果 - [('Dhansagar Bagerhat', {'entities': [[(0, 8)], 'Sarankhola']})]
我的预期输出 - [('Dhansagar Bagerhat', {'entities': [[(0, 8)], 'Sarankhola'],[[(10, 17)], 'AnyLabel']})]
如何获得所有行的输出?我只得到一排的结果。看来我的循环不起作用。谁能指出我的错误?
我的 csv 文件如下所示。 “AnyLabel”是另一列。我有大约 500 行 -
unions subdistrict district
Dhansagar Sarankhola Bagerhat
Daibagnyahati Morrelganj Bagerhat
Ramchandrapur Morrelganj Bagerhat
Kodalia Mollahat Bagerhat
【问题讨论】:
-
向我们展示原始数据框。
-
能否将其复制并粘贴为文本?
-
是的,我已经添加了文本格式
标签: python pandas list dataframe loops