[英]How to acesses dictionary elements within a pandas dataframe column and iterate over them too create new columns filled with their respective values?
I have a pandas dataframe with a column that contains a dictionary, I'd like to iterate over the dictionary keys to create new columns named after the various keys.我有一个 pandas dataframe 和一个包含字典的列,我想遍历字典键以创建以各种键命名的新列。 The issue come whens I try to get the nested list logic to fill those row values with the corresponding key values from the 'tags' column.
当我尝试获取嵌套列表逻辑以使用“标签”列中的相应键值填充这些行值时,问题就出现了。 Right now the code I have generates the column names, but fills all the rows with the same values.
现在我的代码生成列名,但用相同的值填充所有行。 I thought.get() was supposed to retrieve the corresponding value on each iteration?
我以为 get() 应该在每次迭代时检索相应的值?
for x in df1['tags']:
for e in x.values():
df1[str(e)] = x.get(e)
for i, row in df1.iterrows():
for e in row['tags']:
df1.loc[i, e] = row['tags'][e]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.