Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A few lines to make your_off-facebook_activity.json easier to read
#!/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
You can’t perform that action at this time.