我有一个Pandas系列,每行都有一个列表元素。 我想列出这些值并将它们存储回系列中。 看起来像这样。有人可以帮忙吗?
0 ['Harvard business review']
1 ['Harvard business review']
2 ['Journal of Medical Marketing: Device, Diagno...
3 ['Harvard business review']
4 ['Science Translational Medicine']
5 ['Science Translational Medicine']
6 ['Tetrahedron']
7 ['Tetrahedron']
8 ['bioRxiv']
9 ['Science']
10 ['Cell Systems']
11 ['Prescriber']
12 ['Cell']
我尝试将每个转换为列表,然后提取值,但不会转换为列表。
答案 0 :(得分:0)
使用:
import ast
df['column_name']=ast.literal_eval(df['column_name'])
df['column_name'].str[0]
或者如果类型是对象,则可以尝试:
df['column_name'].str.extract('(\[(.*?)\])',expand=False)