Last active
March 16, 2025 22:02
-
-
Save unkwn1-repo/b0f2d4ea6bdd770e5e9e94d54154c751 to your computer and use it in GitHub Desktop.
Simple JSON to CSV Method for Twitter Archive Data
This file contains hidden or 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 python3 | |
''' | |
IMPORTANT: Please delete the following from the tweet.js file before using this: | |
---> window.YTD.tweet.part0 = <---- | |
Whilst that remains you cant parse it easily with json.load | |
''' | |
import pandas as pd | |
import json | |
from pandas.io.json import json_normalize | |
# process raw json | |
data = json.load(open('tweet.js')) | |
# Create DataFrame | |
df = pd.DataFrame.from_records(json_normalize(data)) | |
# Write to CSV | |
df.to_csv("tweets.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very handy- had to tweak a bit with python 3 on OS X 13.4.1