当值是`list`时`pandas.Series.str`是如何工作的?

问题描述 投票:0回答:1

这是如何工作的?如果将每个项目都转换为字符串,我应该得到第一个字符,例如"[1,2]"[0] ----> '[',但是将其视为list,如何?

>>> df = pd.DataFrame({'a':[[1,2],[2,3]]})
>>> df.a.str[0]
0    1
1    2
Name: a, dtype: int64
python pandas series
1个回答
1
投票

[起作用,因为stringlistiterables。这意味着.str[0]返回字符串的第一个值,列表的第一个值,可迭代的第一个值。

© www.soinside.com 2019 - 2024. All rights reserved.