2024-04-25 09:23:10 发布
网友
我有这样的数据帧df:
df
date item 2019-03-29 [book,pencil] ...
我想用循环得到列表中的每一项。这就是我尝试过的:
for i in range(len(df)): for x in df['attributeName'][i]: print(x)
但我有每一个角色。所需输出为:
book pencil
如何解决这个问题?你知道吗
df2['item'].apply(pd.Series).unstack().reset_index(drop=True)
更好的选择。。A Common Pitfall: Exploding Columns of Lists
pd.DataFrame(df2['item'].tolist()).unstack().reset_index(drop=True)
输出
0 book 1 pencil dtype: object
更好的选择。。A Common Pitfall: Exploding Columns of Lists
输出
相关问题 更多 >
编程相关推荐