用Python从一系列列表中选择项目

2024-04-16 19:29:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望能够使用python选择一系列列表的某些部分

我现在有一个类似这样的数据集

0    [s, d, g]
1    [f, g, d]
2       [d, s]
dtype: object

我想为每一行选择一个子集。在我的特殊情况下,我希望能够选择前两个条目。所以要创造一个看起来像

0    [s, d]
1    [f, g]
2    [d, s]
dtype: object

我试过了

for i in Series:
    i = Series[:1]

比如

Series = Series[[:1]]

但很明显我不知道我在这里做什么


Tags: 数据in列表forobject情况条目子集