Data · Code · Interpretation

Introduction to Data Science

How do we turn data into a researchable question, a checkable analysis, and a conclusion we can explain?

This course is being built. Only some of the units are published; the rest are marked ‘in preparation’. What is published is complete and can be studied now.

Learning materials and visual explanations

  1. Databases: SQL and ORM

    Available

    Store, query, and change data with SQL (a language for databases), then connect tables to Python objects with an ORM (object-relational mapper).

    1. 2.1LessonA Practical SQL Guide with DB Browser, Part 1: Retrieve and AnalyzeOpen a real bike-share database in DB Browser, then retrieve, filter, sort, summarize and group rows to see when demand is highest.
    2. 2.2LessonA Practical SQL Guide with DB Browser, Part 2: Change Data and Combine TablesChange data safely, combine tables with JOIN, export results, and use the whole toolbox to answer the bike-share capacity question.
      Practice pages (5)
      1. 2.2.1ExerciseSQL Practice: Review and Back to the Practical Question (Bike Rides)Review the whole toolbox of the SQL guide on the bike-share database, then answer the practical question: when does a bike-share system need capacity?
      2. 2.2.2ExerciseSQL Practice: Two Tables, One Key (Weather and Bike Rides)Practice JOIN on a small two-table database: a table of days that holds a number, and a lookup table that says what the number means. Show, filter and average by the name, not by the number.
      3. 2.2.3ExerciseSQL Practice: Where New Immigrants Settled in IsraelPractice SELECT, JOIN, GROUP BY, HAVING and NULL on open government data about new immigrants and the localities that absorbed them, and learn to check a table before trusting a total.
      4. 2.2.4ExerciseSQL Practice: S&P 500 Companies and Their FilingsPractice SELECT, GROUP BY, HAVING, and UPDATE on real company data, and learn to check whether a number is believable before using it.
      5. 2.2.5ExerciseSQL Exercises: A Question GeneratorPractice SQL on as many questions as you like: write a query in the browser, get it checked, and learn from feedback on what is wrong.
    3. 2.3LessonThe minimum Python for working with SQLiteThe Python that a first program needs in order to ask a SQLite database a question: values and text, tuples, connect, cursor, execute and fetch, parameters, functions that query, and max with a key.
    4. 2.4LessonPython for Databases 1: Values, Variables and CollectionsHow Python holds one row and a whole table of bike-share data: values, variables, text, lists, tuples and dictionaries, the first step before using SQL from Python.
    5. 2.5LessonPython for Databases 2: Loops and FunctionsHow a Python program goes over the rows of a table, decides about each one, and packs a piece of work into a function with parameters and a sorting key.
    6. 2.6LessonPython for Databases 3: Objects and Generator ExpressionsA minimal class turns a table row into an object, and a generator expression asks a question about many objects in one line: the two ideas behind object-relational mapping.
    7. 2.7LessonSQL from Python: Queries, Parameters and Saving ChangesSend SQL queries to a SQLite database from a Python program with the sqlite3 module: connect, execute, fetch rows, pass values safely with parameters, and save or cancel changes.
    8. 2.8LessonTables as Python Objects: A First Look at Pony ORMDescribe a database table as a Python class, add, read, summarize, change and delete rows as objects, and let Pony ORM write the SQL from a generator expression.
    9. 2.9LessonPony ORM Relations: A Table That Points to Another TableConnect two tables that point to each other as Python classes with Pony ORM, follow the relation in both directions, read the SQL that runs, and load related rows from a CSV file, with real World Bank data.
  2. Data Collection: Web Crawling and APIs

    Available

    Collect data from the web by reading pages and calling APIs (interfaces through which a service shares data with programs).

    1. 3.1LessonFrom a Web Page to Data: Beautiful SoupRequest a real web page with Python, see how its tags are organized, and use Beautiful Soup to find one element of a real arXiv page and read its text and its link.
    2. 3.2LessonFrom One Element to All Entries: find_all, Numbers and Missing ValuesRead every entry of a real arXiv list with Beautiful Soup: find_all and a list comprehension, the number of authors of each paper, the maximum and the mean, text that becomes a number, and entries that do not have a value.
    3. 3.3LessonSelf-studyFrom a List to Many Pages: Following LinksFollow the links of a real arXiv list to the page of each paper, read attributes of meta tags, turn text such as 3,330 KB into numbers, handle a missing element, and compute the maximum and the mean over the scraped values.
    4. 3.4LessonPatterns in Text: Regular ExpressionsFind numbers, identifiers, dates and codes inside the text of real arXiv pages with Python regular expressions: raw strings, re.search and re.findall, character classes, quantifiers, groups and the shortest match, and when Beautiful Soup is the better tool.
      Practice pages (1)
      1. 3.4.1ExerciseRegular Expression Lab: Practice on Real arXiv TextA lab for regular expressions: type a pattern, see what it fits in real text from arXiv, and read an explanation of every part of the pattern. Five challenges on the numbers of pages, identifiers, sizes, dates and subject codes.
    5. 3.5LessonAsking a Service for Data: an API and JSONAsk the Wikipedia API about real hardware pages with requests: an endpoint and parameters, the status code, a user agent, an answer in JSON, nested dictionaries and lists, a key that is missing, and a package that asks for us.
      Practice pages (1)
      1. 3.5.1Application and depthA Library of Your Own for an APIChoose a service with an API, build a small library for it with an AI tool, test it against the real service and keep it in your portfolio.
  3. Tabular Analysis with NumPy and pandas

    Available

    Calculate on whole arrays, then read, select, group, pivot, merge and clean tables with NumPy and pandas.

    1. 4.1LessonNumPy Arrays: Calculating on a Whole Column of NumbersConvert the fuel use and weight of 398 real car models with NumPy arrays instead of loops: arithmetic on a whole array, shape and type, indexing and slicing of a table, a boolean mask, a statistic per column or per row, missing values, and a slice that is a view.
    2. 4.2LessonA Table in pandas: Reading, Selecting and FilteringRead 398 real car models into a pandas table: a first look, a column as a Series, rows by label and by position, filtering with conditions, sorting and counting, and the same question in SQL and in pandas.
    3. 4.3LessonNew Columns and Groups in pandasA column computed from other columns and a rule applied with apply, on real car models; then one summary for each group of rows, on real planets outside the Solar System: groupby with one statistic, the grouped result and reset_index, size against count, agg, the size of a group next to its mean, and GROUP BY of SQL next to groupby.
    4. 4.4LessonGroups by Two Columns and Pivot Tables in pandasA summary by two columns, on real exoplanet discoveries, real car models and Iowa electricity generation: groupby with two columns and labels in two levels, the top groups, a question in four steps, pivot_table with aggfunc and fill_value, an empty cell, a mean in each cell, and a long table of records turned into a wide one.
    5. 4.5LessonMerging Tables and Repeated Rows in pandasAdd columns from a second table, and check the rows that repeat, on real exoplanet discoveries and real car models: a lookup table built with pd.DataFrame, merge with on and how, a check of the number of rows, a key with no match, a repeated key and validate, how=outer, merge next to the JOIN of SQL, and repeated rows with duplicated, drop_duplicates, subset and keep.
    6. 4.6LessonMissing Values and Checks Before Computing in pandasA check of a real table before any calculation, on 1,035 rows of planets outside the Solar System and 398 car models: counting the gaps with isna, a share from a 0/1 column, removing rows with dropna and subset, filling with fillna and what it changes, copy before a change, numbers stored as text, and five lines of code before an analysis.
  4. Large Data

    In preparation

    Work with data that is too large to handle in one piece: read only what is needed, save memory, process in parts, and choose a tool.

  5. Static and Interactive Visualization

    In preparation

    Choose, build, and read charts, from fixed figures to charts you can explore.

  6. Networks and Graph Mining

    In preparation

    Networks of nodes and edges: which nodes matter most, how communities form, and what can be learned from the structure.

  7. Text Analysis

    In preparation

    Text as data: word counts, TF-IDF (which words characterize a document), topic discovery, and named entities.

For the whole course

These materials supplement the teaching in the course. The syllabus, deadlines, assessment instructions, and group announcements are published in the institution’s course system.