Data Format and Management¶
In this module, you will learn how social media data is stored: the file formats that APIs return and that analysis tools read, and the databases that hold a collection once files are no longer enough.
Every platform API returns JSON. Every analysis tool wants a table. Most of the work between collecting data and analyzing it is moving records between those two shapes without losing anything on the way.
Learning objectives¶
- Read and write JSON, JSONL, CSV, and Parquet files in Python
- Choose a format for raw data, for analysis tables, and for sharing
- Inspect a data file from the command line before writing code for it
- Recognize the common failures: text encoding, quoting, lost leading zeros, broken JSON, and files too large for memory
- Convert nested JSON into tables, and tables back into JSON
- Explain what a database adds over files: search, integrity, concurrency, and crash recovery
- Design relational tables for social media data and query them with SQL
- Decide when PostgreSQL is enough and when a NoSQL database fits better
Pages¶
| Page | What it covers |
|---|---|
| Choosing a format | JSON, JSONL, CSV, and Parquet: what each is for and how they compare; JSON versus tables; compression; a storage layout for a collector |
| Command-line tools | Look at a file before writing code: head, wc, jq, bat, gzip, and the questions to ask of a new file |
| Pitfalls | Encoding, quoting, data types, broken JSON, validation, memory, and spreadsheets |
| Databases | Why files stop being enough; the relational model, SQL, indexes, transactions; PostgreSQL and psycopg; NoSQL databases and when to use them |
| Modeling social media data | Table designs for 4chan, YouTube, and Bluesky, and a cross-platform worked example |
Notebooks¶
The notebooks use small sample files that they download on first run, so they work in Colab without setup.
Related¶
- Data collection, whose notebooks produce the JSON that this module stores and converts
- Build Your Own Pipeline, a guide to a full pipeline, including how to store what a collector produces