gpt4 book ai didi

python - 使用 Python 分隔字段内的逗号分隔文本

转载 作者:行者123 更新时间:2023-11-28 21:29:13 25 4
gpt4 key购买 nike

我目前正在尝试使用Python 将表格转换为RDF,并将每个单元格的值附加到URL 的末尾(例如,E00 变为statistics.data.gov.uk/id/statistical-geography/E00)。

我可以使用脚本对包含单个值的单元格执行此操作。

FirstCode = row[11]

if row[11] != '':

RDF = RDF + '<http://statistics.data.gov.uk/id/statistical-geography/' + FirstCode + '>.\n'

数据库中的一个字段包含多个以逗号分隔的值。因此,上面的代码返回附加到 URL 的所有代码

例如http://statistics.data.gov.uk/id/statistical-geography/E00,W00,S00

而我希望它返回三个值

statistics.data.gov.uk/id/statistical-geography/E00
statistics.data.gov.uk/id/statistical-geography/W00
statistics.data.gov.uk/id/statistical-geography/S00

是否有一些代码可以让我将它们分开?

最佳答案

是的,有split方法。

FirstCode.split(",")

将返回一个类似(E00, W00, S00)的列表

您可以迭代列表中的项目:

 for i in FirstCode.split(","):
print i

将打印出:E00W00S00

This page还有一些其他有用的字符串函数

关于python - 使用 Python 分隔字段内的逗号分隔文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6077429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com