Beginner_Data_Analytics_Python_Colab1.ipynb

{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Beginner Workshop: Data Analytics with Python in Google Colab\n", "**Audience:** No prior Python experience \n", "**Dataset:** `student_survey_synthetic.csv` (synthetic, fictional records)\n", "\n", "## How to use this notebook\n", "1. Open [Google Colab](https://colab.research.google.com/).\n", "2. Choose **File \u2192 Upload notebook** and upload this `.ipynb` file, or open it in Colab.\n", "3. Upload `student_survey_synthetic.csv` when prompted in the data-loading section.\n", "4. Run cells from top to bottom using the play button. You do not need to memorize the code.\n", "\n", "**Learning goals:** Load a CSV, inspect and clean data, summarize variables, create charts, and communicate one evidence-based finding." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 1 \u2014 What is data analytics? (0:00\u20130:20)\n", "Data analytics means using data to answer a question. A simple workflow is:\n", "**Ask a question \u2192 collect data \u2192 inspect/clean \u2192 analyze \u2192 visualize \u2192 explain limitations.**\n", "\n", "Example questions:\n", "- What is the typical course score?\n", "- Do scores differ by class engagement category?\n", "- Is study time associated with course score?\n", "\n", "The dataset is artificial and designed for practice. It must not be used to make real decisions about students." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 2 \u2014 Python essentials (0:20\u20130:45)\n", "Python runs one instruction at a time. A variable gives a value a readable name. Text is written in quotes; numbers are not." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your first Python expressions\n", "print(\"Hello, data analytics!\")\n", "workshop_name = \"Data Analytics with Python\"\n", "students_in_example = 120\n", "print(workshop_name)\n", "print(\"Number of rows in the example dataset:\", students_in_example)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Try it" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Change the workshop name, then run the cell again. Try changing `students_in_example` to another number." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# A tiny calculation\n", "study_hours = 6\n", "days = 5\n", "print(\"Study hours over five days:\", study_hours * days)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 3 \u2014 Load and inspect data (0:45\u20131:15)\n", "We will use **pandas**, a Python library for working with tables, and **matplotlib** for charts. Both are available in Google Colab." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from google.colab import files\n", "\n", "uploaded = files.upload() # Select student_survey_synthetic.csv from your computer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Read the uploaded CSV into a table called df\n", "df = pd.read_csv(\"student_survey_synthetic.csv\")\n", "\n", "# Preview rows and check the size of the dataset\n", "display(df.head())\n", "print(\"Rows and columns:\", df.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Learn what each column contains\n", "df.info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Summary statistics for numeric columns\n", "display(df.describe())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What to notice\n", "- Each row represents one fictional survey record.\n", "- Each column is a variable.\n", "- `head()` shows a preview; `shape` reports rows and columns; `describe()` summarizes numeric columns." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 4 \u2014 Clean the data (1:15\u20131:35)\n", "Missing values are common. First count them; then decide how to handle them. For this introductory exercise, we will create a cleaned copy and fill missing numeric values with their column medians and missing categories with their most frequent value." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Count missing values in each column\n", "print(df.isna().sum())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Keep the original data unchanged and clean a copy\n", "clean_df = df.copy()\n", "\n", "numeric_columns = clean_df.select_dtypes(include=\"number\").columns\n", "for column in numeric_columns:\n", " clean_df[column] = clean_df[column].fillna(clean_df[column].median())\n", "\n", "categorical_columns = clean_df.select_dtypes(include=\"object\").columns\n", "for column in categorical_columns:\n", " clean_df[column] = clean_df[column].fillna(clean_df[column].mode()[0])\n", "\n", "print(\"Missing values after this simple cleaning step:\")\n", "print(clean_df.isna().sum())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Important:** Filling missing values is a choice, not a universal rule. In real projects, explain why a method is appropriate and consider whether missingness itself is meaningful." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 5 \u2014 Ask questions and summarize (1:35\u20132:05)\n", "We will use averages and group summaries to explore the dataset. These summaries describe this synthetic sample; they do not establish cause and effect." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Typical score and study time\n", "print(\"Average course score:\", round(clean_df[\"course_score\"].mean(), 1))\n", "print(\"Median course score:\", round(clean_df[\"course_score\"].median(), 1))\n", "print(\"Average weekly study hours:\", round(clean_df[\"study_hours_per_week\"].mean(), 1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Compare average scores across engagement categories\n", "engagement_summary = (\n", " clean_df.groupby(\"class_engagement\")[\"course_score\"]\n", " .agg([\"count\", \"mean\", \"median\"])\n", " .round(1)\n", ")\n", "display(engagement_summary)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Compare average scores by major\n", "major_summary = (\n", " clean_df.groupby(\"major\")[\"course_score\"]\n", " .mean()\n", " .sort_values(ascending=False)\n", " .round(1)\n", ")\n", "display(major_summary)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Pair discussion\n", "1. Which group has the highest average score in this sample?\n", "2. How large is the difference between the highest and lowest group averages?\n", "3. What other information would you want before drawing a conclusion?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 6 \u2014 Visualize the data (2:05\u20132:35)\n", "Charts help us see patterns. Choose a chart that fits the question and label it clearly." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Histogram: distribution of course scores\n", "plt.figure(figsize=(7, 4))\n", "plt.hist(clean_df[\"course_score\"], bins=10, edgecolor=\"black\")\n", "plt.title(\"Distribution of Course Scores\")\n", "plt.xlabel(\"Course score\")\n", "plt.ylabel(\"Number of records\")\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Bar chart: average course score by engagement category\n", "avg_by_engagement = clean_df.groupby(\"class_engagement\")[\"course_score\"].mean().sort_values()\n", "avg_by_engagement.plot(kind=\"bar\", figsize=(7, 4))\n", "plt.title(\"Average Course Score by Class Engagement\")\n", "plt.xlabel(\"Class engagement\")\n", "plt.ylabel(\"Average course score\")\n", "plt.xticks(rotation=0)\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Scatter plot: weekly study hours and course score\n", "plt.figure(figsize=(7, 4))\n", "plt.scatter(clean_df[\"study_hours_per_week\"], clean_df[\"course_score\"], alpha=0.7)\n", "plt.title(\"Study Hours and Course Score\")\n", "plt.xlabel(\"Study hours per week\")\n", "plt.ylabel(\"Course score\")\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 7 \u2014 Mini-capstone (2:35\u20132:55)\n", "Choose one question and complete the steps below:\n", "- Does attendance percentage appear associated with course score?\n", "- How does average study time differ by class year?\n", "- Which major has the largest spread in course scores?\n", "- Does sleep duration appear associated with course score?\n", "\n", "**Deliverable:** one chart, two descriptive statistics, and a 3\u20134 sentence interpretation. State one limitation and avoid claiming that one variable causes another." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Starter template: replace the column names or group variable to investigate your question\n", "print(clean_df[[\"attendance_percent\", \"course_score\"]].corr().round(2))\n", "\n", "plt.figure(figsize=(7, 4))\n", "plt.scatter(clean_df[\"attendance_percent\"], clean_df[\"course_score\"], alpha=0.7)\n", "plt.title(\"Attendance Percentage and Course Score\")\n", "plt.xlabel(\"Attendance (%)\")\n", "plt.ylabel(\"Course score\")\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exit ticket (2:55\u20133:00)\n", "Answer in plain language:\n", "1. What is one thing you learned from the data?\n", "2. Which chart or summary helped you answer your question?\n", "3. What is one reason not to overgeneralize from this dataset?\n", "\n", "## Instructor notes\n", "- Keep the focus on interpreting results, not memorizing syntax.\n", "- Pause frequently; invite learners to predict what a cell will do before running it.\n", "- If upload is difficult, use the following fallback cell to generate/load the same dataset only if the CSV is already in the Colab session.\n", "- The data are fully synthetic. The relationships are illustrative and should not be interpreted as findings about real students." ] } ], "metadata": { "colab": { "name": "Beginner_Data_Analytics_Python_Colab.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }