擅长:python、mysql、java
<p>您可以使用<code>np.size</code>:</p>
<pre><code>In [301]: file = pd.Series([['junior','senior'], 'freshgrad'])
In [302]: file.apply(np.size)
Out[302]:
0 2
1 1
dtype: int64
In [327]: np.size(file[0])
Out[327]: 2
In [328]: np.size(file[1])
Out[328]: 1
</code></pre>
<p>但在某种程度上,这可能只是拖延你的痛苦。当物体
一个序列(或任何类型的序列)有不同的类型,代码往往需要进行类型检查或<code>try..except</code>以不同的方式处理各种类型。(事实上,这就是<code>np.size</code>正在做的。在引擎盖下<code>np.size</code>正在使用<code>try..except</code>来处理异常情况。)</p>
<p>当序列中的所有对象都具有相同的类型时,生活通常更简单(因此更好)。因此,最好构建一个系列,其元素都是列表:</p>
<pre><code>In [301]: file = pd.Series([['junior','senior'], ['freshgrad']])
</code></pre>