我有一个csv文件如下
h1,h2,h3
1 year,homo sapiens,fibrous tissue
3 minutes,homo sapiens,fibrous tissue
2 hours,homo sapiens,epithelial tissue
我只想得到包含我提供的字符串的列。例如,如果我说year,则需要将整个列追加到一个列表中,比如[1year,3minutes,2hours]。我完全不知道该怎么办。我真的很感谢你的帮助。在
编辑:问题是,数据可以在任何列中。在
Tags:
我们可以使用列表理解和
any
和str.contains
的组合:因此,通过调用向量化的} 来测试列中的
str
方法^{any
值是否包含感兴趣的文本。在很容易将列表理解打包到返回列表的函数中:
^{pr2}$试试这个
输出 h1
1年
3分钟
2小时
^{pr2}$输出:
氢气
智人
智人
智人
相关问题 更多 >
编程相关推荐