如何列出特定列的列表

发布于 2025-02-11 03:41:27 字数 148 浏览 3 评论 0原文

我有一个列表,如下所示。如何仅列出输出的第三列(以0.002147开头的列表)这就是我的输出的方式

I have a list of linelists file as below.how do i make a list of only the 3rd column of the output(the one starting with 0.002147)this is how my output is

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2025-02-18 03:41:27

假设线词看起来像这样:

l = ['col11\tcol21\tcol31\tcol41\tcol51',
     'col12\tcol22\tcol32\tcol42\tcol52']

第三列

您可以使用col3list = [line.split(“ \ t”)[2]的

[l] ,它可以使您 ['col31 ','col32'] 。

基于您提供的图像,尚不清楚列是否被选项卡或多个空格分开。如果分离器是空格,则需要更改拆分函数的参数。

与您的问题类似的事情也已经回答了在这里

通常,我建议使用python库

Assuming linelists looks something like this:

l = ['col11\tcol21\tcol31\tcol41\tcol51',
     'col12\tcol22\tcol32\tcol42\tcol52']

you can select the third column with

col3list = [line.split("\t")[2] for line in l]

which gives you ['col31', 'col32'].

Based on the image you provided, it is not clear if the columns are separated by a tab or multiple spaces. If the separators are spaces, you would need to change the argument of the split function.

Something similar to your question was also already answered here.

In general I would recommend loading files with the python library pandas, which can handle all kinds of data loading and selection tasks for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文