擅长:python、mysql、java
<p>一种简单的方法,如果您不想求助于<code>ast</code>(例如,为了避免解析非列表的内容):</p>
<pre><code>from io import StringIO
inp = """ x y
[133,28,23] female
[157,22,87] male
[160,33,77] male
[122,87,20] female
[120,22,20] female"""
# Read data
df = pd.read_csv(StringIO(inp), delim_whitespace=True, header=0)
# Remove brackets, split and convert to int
df.x = df.x.map(lambda el: list(map(int, el.strip()[1:-1].split(','))))
# Print
l1 = [h for h in df.x]
print(l1)
</code></pre>
<p>输出:</p>
<pre class="lang-none prettyprint-override"><code>[[133, 28, 23], [157, 22, 87], [160, 33, 77], [122, 87, 20], [120, 22, 20]]
</code></pre>