skip to Main Content

dataframe

Trying to extract the username from the author column of the dataframe for each row, the author column is series & the individual values inside author is a dictionary.

Converting the author column directly to df & & changing the type of author column not helping to reach the goal.

I’m only able to reference the username via

df_item['author'][0]['username']

Trying to get a separate username column

id                  type   content        channel_id           username
1047404831062638613 0      It’s really..   1047331843898359849  lips
1047333443165499432 0      okay,thankyou   1047331843898359849   Mj

2

Answers


  1. Chosen as BEST ANSWER

    First convert the series to list then pass it to pandas dataframe and it takes care of the rest.

    df_new = DataFrame(list(df2["author"]))
    

  2. Did you try this:

    df['author_username'] = df['author'].apply(lambda x: x['username'])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search