KAHIBARO Bookshelves
Discord Login Register

17.6. Small web or data project

Choosing Your Small Project

In this chapter you’ll build one small project that uses what you’ve learned so far. You can choose:

  • A tiny web project (using Flask)
  • A tiny data project (using pandas / matplotlib)

You do not need to build both. Pick one that sounds more fun or useful to you.

We’ll walk through:

  1. A simple web project idea and how to build it.
  2. A simple data project idea and how to build it.
  3. How to extend your chosen project.

You can treat this chapter as a “recipe”: follow it once as written, then modify it.


Option 1: Tiny Web Project – Personal Notes Web App

Project idea

Build a very simple “personal notes” web app where you can:

  • Open a page in your browser.
  • Type a short note into a form.
  • See all saved notes listed on the page.

We’ll keep everything in memory (a Python list), so when you stop the program, the notes disappear. This keeps the code short and focused.

You should already have seen in the web chapters:

  • How to install and run Flask.
  • What routes and templates are.

Here we just put those pieces together into a complete mini-project.

Project structure

Create a folder for your project, for example:

  • notes_app/
    • app.py
    • templates/
      • index.html

You run app.py, then open the app in your browser.

Step 1: Basic Flask app and home page

In app.py:

from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
# This list will store our notes while the app is running
notes = []
@app.route("/", methods=["GET"])
def index():
    return render_template("index.html", notes=notes)
if __name__ == "__main__":
    app.run(debug=True)

Create the templates folder, and inside it create index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>My Notes</title>
</head>
<body>
    <h1>My Notes</h1>
    <!-- Form to add a new note -->
    <form method="post" action="{{ url_for('add_note') }}">
        <input type="text" name="note_text" placeholder="Write a note..." required>
        <button type="submit">Add</button>
    </form>
    <h2>Saved notes:</h2>
    <ul>
        {% for note in notes %}
            <li>{{ note }}</li>
        {% else %}
            <li>No notes yet.</li>
        {% endfor %}
    </ul>
</body>
</html>

If you run app.py now, it will fail because we haven’t defined the add_note route yet. That’s the next step.

Step 2: Handling the form (adding notes)

Add a new route in app.py before the if __name__ == "__main__": line:

@app.route("/add", methods=["POST"])
def add_note():
    note_text = request.form.get("note_text", "").strip()
    if note_text:
        notes.append(note_text)
    # Redirect back to the home page so the user sees the updated list
    return redirect(url_for("index"))

Now update the form in index.html to match the /add route if needed (we already used url_for('add_note'), so it should be fine).

Your full app.py now:

from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
notes = []  # in-memory storage
@app.route("/", methods=["GET"])
def index():
    return render_template("index.html", notes=notes)
@app.route("/add", methods=["POST"])
def add_note():
    note_text = request.form.get("note_text", "").strip()
    if note_text:
        notes.append(note_text)
    return redirect(url_for("index"))
if __name__ == "__main__":
    app.run(debug=True)

Run python app.py, open the URL shown in the terminal (usually http://127.0.0.1:5000/), and:

  • Type a note.
  • Click “Add”.
  • See it appear in the list.

Step 3: Adding a “delete note” feature

Let’s allow deleting individual notes by index. We’ll:

  • Display a delete button next to each note.
  • Send its index to a /delete/<index> route.

In app.py add:

@app.route("/delete/<int:index>", methods=["POST"])
def delete_note(index):
    if 0 <= index < len(notes):
        notes.pop(index)
    return redirect(url_for("index"))

Update index.html to include a delete form for each note:

<ul>
    {% for note in notes %}
        <li>
            {{ loop.index0 }}. {{ note }}
            <form method="post" action="{{ url_for('delete_note', index=loop.index0) }}"
                  style="display:inline">
                <button type="submit">Delete</button>
            </form>
        </li>
    {% else %}
        <li>No notes yet.</li>
    {% endfor %}
</ul>

Now you have:

  • A web form to add notes.
  • A list that updates.
  • A way to delete notes.

This is a complete small web project.

Ideas to extend the web project

Pick 1–2 small improvements:

  • Add timestamps to notes using datetime.
  • Limit note length, and show a message if it’s too long.
  • Add a second page, e.g. /about, explaining what the app is.
  • Save notes to a file (use the file chapter) so they persist between runs.
  • Style the page with basic CSS.

Option 2: Tiny Data Project – Simple CSV Data Explorer

Project idea

Build a small script that:

  1. Loads data from a CSV file using pandas.
  2. Shows basic statistics (count, mean, min, max).
  3. Creates a simple plot using matplotlib.
  4. Interacts with the user via the terminal (user chooses what to see).

You already saw the basics of pandas and matplotlib; here we combine them into a single usable script.

We’ll assume:

  • You can install packages with pip.
  • You have a CSV file or can download one.

Setup

Install needed libraries (if not already installed):

pip install pandas matplotlib

Pick a CSV file, for example:

  • A small dataset you downloaded (e.g. from Kaggle).
  • Or create your own data.csv like:
name,age,score
Alice,23,88
Bob,30,92
Charlie,25,79
Diana,28,95

Place data.csv in the same folder as your script.

Step 1: Load and briefly inspect the data

Create data_explorer.py:

import pandas as pd
FILE_NAME = "data.csv"
def load_data():
    try:
        df = pd.read_csv(FILE_NAME)
        print(f"Loaded {len(df)} rows from {FILE_NAME}")
        return df
    except FileNotFoundError:
        print(f"ERROR: Could not find file {FILE_NAME}")
        return None

Run it interactively to check that loading works (for now, just print “Loaded ... rows”).

Step 2: Show basic info and statistics

Add functions to inspect the data:

def show_basic_info(df):
    print("\n--- Basic Information ---")
    print(df.info())  # shows column names and types
def show_summary(df):
    print("\n--- Summary Statistics (numeric columns) ---")
    print(df.describe())  # count, mean, std, min, max, etc.

Now create a simple menu to let the user choose actions.

Step 3: Simple text menu

Add a function:

def main_menu(df):
    while True:
        print("\nWhat would you like to do?")
        print("1) Show first 5 rows")
        print("2) Show basic info")
        print("3) Show summary statistics")
        print("4) Plot a numeric column")
        print("5) Quit")
        choice = input("Enter your choice (1-5): ").strip()
        if choice == "1":
            print("\n--- First 5 rows ---")
            print(df.head())
        elif choice == "2":
            show_basic_info(df)
        elif choice == "3":
            show_summary(df)
        elif choice == "4":
            plot_column(df)
        elif choice == "5":
            print("Goodbye!")
            break
        else:
            print("Invalid choice, please try again.")

We still need plot_column(df), which will use matplotlib.

Step 4: Simple plotting

At the top of the file, add:

import matplotlib.pyplot as plt

Now implement plot_column:

def plot_column(df):
    print("\nAvailable columns:")
    for col in df.columns:
        print(f"- {col}")
    column_name = input("Enter the name of a numeric column to plot: ").strip()
    if column_name not in df.columns:
        print(f"Column '{column_name}' does not exist.")
        return
    if not pd.api.types.is_numeric_dtype(df[column_name]):
        print(f"Column '{column_name}' is not numeric and cannot be plotted as a line chart.")
        return
    print(f"Plotting column '{column_name}'...")
    df[column_name].plot(kind="line", title=column_name)
    plt.xlabel("Row index")
    plt.ylabel(column_name)
    plt.show()

This:

  • Lists available columns.
  • Asks the user which column to plot.
  • Checks that the column exists and is numeric.
  • Plots a simple line chart.

Step 5: Wire everything together

Add a main() that uses all these pieces:

def main():
    df = load_data()
    if df is None:
        return
    print("\nPreview of the data:")
    print(df.head())
    main_menu(df)
if __name__ == "__main__":
    main()

Run:

python data_explorer.py

Try different menu options and plot a column.

Ideas to extend the data project

Possible improvements:

  • Ask the user for the file name instead of hardcoding data.csv.
  • Add an option to filter rows, for example:
    • “Show rows where age > 25”
  • Let the user save filtered data to a new CSV file:
    • Use df.to_csv("filtered.csv", index=False)
  • Add histogram plots for numeric columns:
    • df[column_name].plot(kind="hist", bins=10)
  • Add an option to sort by a chosen column:
    • df.sort_values(by=column_name)

Picking and Finishing Your Project

To finish this chapter:

  1. Choose one:
    • The notes web app, or
    • The CSV data explorer.
  2. Get the basic version working as shown.
  3. Add at least one small extension of your own:
    • For example, extra route, extra menu option, file saving, styling, etc.
  4. Run and test:
    • Try incorrect input.
    • Try edge cases (empty notes, wrong column name, etc.).

This small project is your bridge from individual exercises to real programs that feel useful and complete, even if they are tiny.

Views: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Chapter 1: What Is Programming?
    • ☰ 1.1. What is a computer program?
      • ☰ 1.2. What is Python?
        • ☰ 1.3. Where is Python used?
          • ☰ 1.4. How programming helps solve problems
            • ☰ 1.5. Your first Python program
            • ☰ 2. Chapter 2: Setting Up Python
              • ☰ 2.1. Installing Python (Windows / macOS / Linux)
                • ☰ 2.2. Using Python in the terminal
                  • ☰ 2.3. Using an IDE (IDLE / VS Code)
                    • ☰ 2.4. Running Python scripts
                      • ☰ 2.5. Python interactive mode
                      • ☰ 3. Chapter 3: Variables and Data Types
                        • ☰ 3.1. What is a variable?
                          • ☰ 3.2. Creating variables
                            • ☰ 3.3. Numbers
                              • ☰ 3.4. Test
                                • ☰ 3.5. Boolean values
                                  • ☰ 3.6. Type checking
                                  • ☰ 4. Chapter 4: Basic Operations
                                    • ☰ 4.1. Arithmetic operations
                                      • ☰ 4.2. Working with numbers
                                        • ☰ 4.3. String operations
                                          • ☰ 4.4. Combining text and variables
                                            • ☰ 4.5. Comments in Python
                                            • ☰ 5. Chapter 5: User Input and Output
                                              • ☰ 5.1. Getting input from the user
                                                • ☰ 5.2. Converting input to numbers
                                                  • ☰ 5.3. Formatting output
                                                    • ☰ 5.4. Writing interactive programs
                                                    • ☰ 6. Chapter 6: Conditions
                                                      • ☰ 6.1. Comparison operators
                                                        • ☰ 6.2. Logical operators
                                                          • ☰ 6.3. if, elif, else
                                                            • ☰ 6.4. Nested conditions
                                                              • ☰ 6.5. Common beginner mistakes
                                                              • ☰ 7. Chapter 7: Loops
                                                                • ☰ 7.1. Why loops are useful
                                                                  • ☰ 7.2. for loops
                                                                    • ☰ 7.3. while loops
                                                                      • ☰ 7.4. Loop counters
                                                                        • ☰ 7.5. break and continue
                                                                          • ☰ 7.6. Loop exercises
                                                                          • ☰ 8. Chapter 8: Data Collections
                                                                            • ☰ 8.1. Lists
                                                                              • ☰ 8.2. Tuples
                                                                                • ☰ 8.3. Dictionaries
                                                                                  • ☰ 8.4. Sets (basics)
                                                                                    • ☰ 8.5. Choosing the right data structure
                                                                                    • ☰ 9. Chapter 9: Functions
                                                                                      • ☰ 9.1. Why functions matter
                                                                                        • ☰ 9.2. Defining functions
                                                                                          • ☰ 9.3. Parameters and arguments
                                                                                            • ☰ 9.4. Return values
                                                                                              • ☰ 9.5. Scope (local vs global)
                                                                                                • ☰ 9.6. Reusing code
                                                                                                • ☰ 10. Chapter 10: Working with Files
                                                                                                  • ☰ 10.1. What is a file?
                                                                                                    • ☰ 10.2. Reading text files
                                                                                                      • ☰ 10.3. Writing and appending files
                                                                                                        • ☰ 10.4. File paths
                                                                                                          • ☰ 10.5. Simple file-based programs
                                                                                                          • ☰ 11. Chapter 11: Errors and Debugging
                                                                                                            • ☰ 11.1. Types of errors
                                                                                                              • ☰ 11.2. Reading error messages
                                                                                                                • ☰ 11.3. Common beginner errors
                                                                                                                  • ☰ 11.4. try and except
                                                                                                                    • ☰ 11.5. Debugging strategies
                                                                                                                    • ☰ 12. Chapter 12: Using Python Libraries
                                                                                                                      • ☰ 12.1. What is a library?
                                                                                                                        • ☰ 12.2. Importing modules
                                                                                                                          • ☰ 12.3. Standard libraries
                                                                                                                            • ☰ 12.3.1. math
                                                                                                                              • ☰ 12.3.2. random
                                                                                                                                • ☰ 12.3.3. datetime
                                                                                                                                • ☰ 12.4. Installing external libraries with pip
                                                                                                                                • ☰ 13. Chapter 13: Object-Oriented Programming
                                                                                                                                  • ☰ 13.1. What is object-oriented programming?
                                                                                                                                    • ☰ 13.2. Classes and objects
                                                                                                                                      • ☰ 13.3. The `__init__` method
                                                                                                                                        • ☰ 13.4. Attributes and methods
                                                                                                                                          • ☰ 13.5. Encapsulation
                                                                                                                                            • ☰ 13.6. Inheritance (basics)
                                                                                                                                              • ☰ 13.7. Simple OOP examples
                                                                                                                                              • ☰ 14. Chapter 14: Automation with Python
                                                                                                                                                • ☰ 14.1. What is automation?
                                                                                                                                                  • ☰ 14.2. Automating simple tasks
                                                                                                                                                    • ☰ 14.3. Working with files and folders
                                                                                                                                                      • ☰ 14.4. Automating text processing
                                                                                                                                                        • ☰ 14.5. Scheduling scripts
                                                                                                                                                          • ☰ 14.6. Practical automation examples
                                                                                                                                                          • ☰ 15. Chapter 15: Web Development with Python
                                                                                                                                                            • ☰ 15.1. How the web works (basic overview)
                                                                                                                                                              • ☰ 15.2. Introduction to Flask
                                                                                                                                                                • ☰ 15.3. Creating a simple web server
                                                                                                                                                                  • ☰ 15.4. Routing and templates
                                                                                                                                                                    • ☰ 15.5. Handling user input (forms)
                                                                                                                                                                      • ☰ 15.6. Very basic APIs
                                                                                                                                                                      • ☰ 16. Chapter 16: Data Science with Python
                                                                                                                                                                        • ☰ 16.1. What is data science?
                                                                                                                                                                          • ☰ 16.2. Working with data
                                                                                                                                                                            • ☰ 16.3. Introduction to NumPy
                                                                                                                                                                              • ☰ 16.4. Introduction to pandas
                                                                                                                                                                                • ☰ 16.5. Data visualization with matplotlib
                                                                                                                                                                                  • ☰ 16.6. Simple data analysis examples
                                                                                                                                                                                  • ☰ 17. Chapter 17: Mini Projects
                                                                                                                                                                                    • ☰ 17.1. Number guessing game
                                                                                                                                                                                      • ☰ 17.2. Simple calculator
                                                                                                                                                                                        • ☰ 17.3. To-do list
                                                                                                                                                                                          • ☰ 17.4. Password generator
                                                                                                                                                                                            • ☰ 17.5. Quiz application
                                                                                                                                                                                              • ☰ 17.6. Small web or data project
                                                                                                                                                                                              • ☰ 18. Chapter 18: Next Steps
                                                                                                                                                                                                • ☰ 18.1. How to practice Python
                                                                                                                                                                                                  • ☰ 18.2. Writing clean and readable code
                                                                                                                                                                                                    • ☰ 18.3. Choosing a specialization
                                                                                                                                                                                                      • ☰ 18.3.1. Web development
                                                                                                                                                                                                        • ☰ 18.3.2. Data science
                                                                                                                                                                                                          • ☰ 18.3.3. Automation
                                                                                                                                                                                                            • ☰ 18.3.4. Software development
                                                                                                                                                                                                            • ☰ 18.4. Learning resources and communities
                                                                                                                                                                                                            • ☰ 19. Appendix
                                                                                                                                                                                                              • ☰ 19.1. Python syntax cheat sheet
                                                                                                                                                                                                                • ☰ 19.2. Common errors and solutions
                                                                                                                                                                                                                  • ☰ 19.3. Glossary of terms