简体   繁体   中英

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. 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?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM