Unpacking the user data

We now do the exact same thing for each piece of user JSON data. We call apply on the user series, running the unpack_user_json function, which takes a JSON user object and transforms it into a list of its fields, which we can then inject into a brand new DataFrameuser_df. After that, we'll join user_df back with df, like we did with campaign_df:

#11def unpack_user_json(user):    # very optimistic as well, expects user objects    # to have all attributes    user = json.loads(user.strip())    return [        user['username'],        user['email'],        user['name'],        user['gender'],        user['age'],        user['address'],    ]user_data = df['user'].apply(unpack_user_json)user_cols = [    'username', 'email', 'name', 'gender', 'age', 'address']user_df = DataFrame( ...

Get Learn Python Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.