我有一个CSV文件,其中包含一列名称。我想要的是一个python代码来检查列中的每个名称,并查看名称是否包含多个部分,它只包含第一个部分并将其附加到新的CSV文件列表中,同时跳过旧CSV文件中仅包含一个部分的任何名称
比如说
输入CSV文件
Column1
Metarhizium robertsii ARSEF 23
Danio rerio
Parascaris equorum
Hevea
Gossypium
Vitis vinifera
输出CSV文件应为
Column1
Metarhizium
Danio
Parascaris
Vitis
名称是否总是用空格分隔
您可以在python中使用
re
模块并使用正则表达式,或者如果您想要简单的东西,也可以在python中使用str.split()
方法:您可以拆分,然后应用函数
len
来屏蔽结果,然后获取行中筛选的第一个元素您可以首先为具有多个单词的值创建一个标志,然后使用
apply()
方法并编写lambda函数来检索所有名称中的第一个单词相关问题 更多 >
编程相关推荐