1 回答
TA贡献1859条经验 获得超6个赞
将值转换为列表,然后转换为DataFrame或Series构造函数:
df_mesh = pd.DataFrame({'terms': [['Algorithms','Brain'],['Adult','Algorithms']]})
print (df_mesh)
terms
0 [Algorithms, Brain]
1 [Adult, Algorithms]
df = pd.DataFrame({'new': [df_mesh['terms'].tolist()]})
print (df)
new
0 [[Algorithms, Brain], [Adult, Algorithms]]
s = pd.Series([df_mesh['terms'].tolist()])
print (s)
0 [[Algorithms, Brain], [Adult, Algorithms]]
dtype: object
编辑:
s1 = pd.Series([[val for sublist in df_mesh['terms'] for val in sublist]])
print (s1)
0 [Algorithms, Brain, Adult, Algorithms]
dtype: object
或者:
s1 = pd.Series([list(itertools.chain.from_iterable(df_mesh['terms']))])
添加回答
举报