Created
January 29, 2020 15:01
-
-
Save palrogg/ebe74275c51488a156d74402327a9f7a to your computer and use it in GitHub Desktop.
A few lines to make your_off-facebook_activity.json easier to read
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# requirements: pandas, xlrd | |
import pandas as pd | |
import json | |
with open('your_off-facebook_activity.json', encoding='utf-8') as f: | |
data = json.load(f) | |
# unnest data | |
rows = [] | |
for provider in data['off_facebook_activity']: | |
for item in provider['events']: | |
item['name'] = provider['name'] | |
rows.append(item) | |
# Unix timestamp to date and time | |
df = pd.DataFrame(rows) | |
df['date'] = pd.to_datetime(df['timestamp'], unit='s') | |
# Save to Excel using xlrd | |
df[['name', 'type', 'date', 'timestamp', 'id']].to_excel('events.xlsx', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment