June 2018
Beginner
508 pages
13h 8m
English
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( ...
Read now
Unlock full access