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 DataFrame, user_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 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.