diff --git a/database/code/read_files.ipynb b/database/code/read_files.ipynb new file mode 100644 index 0000000..445679c --- /dev/null +++ b/database/code/read_files.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "STUDENTS_FILE = \"../data/students.csv\"" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name\n", + "Tantia Tope\n", + "Kilvish\n", + "John Watson\n" + ] + } + ], + "source": [ + "# Read file and print out name of students\n", + "with open(STUDENTS_FILE, \"r\") as file:\n", + " for line in file:\n", + " name = line.split(\",\")[0]\n", + " print(name)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tantia Tope\n", + "Kilvish\n", + "John Watson\n" + ] + } + ], + "source": [ + "# Read file and print just names of students\n", + "with open(STUDENTS_FILE, \"r\") as file:\n", + " for index, line, in enumerate(file):\n", + " if index == 0:\n", + " continue\n", + " name = line.split(\",\")[0]\n", + " print(name)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tantia Tope 20\n", + "Kilvish 21\n" + ] + } + ], + "source": [ + "# Read file and only print users with age less than 25\n", + "with open(STUDENTS_FILE, \"r\") as file:\n", + " for index, line, in enumerate(file):\n", + " if index == 0:\n", + " continue\n", + " name = line.split(\",\")[0]\n", + " age = line.split(\",\")[3]\n", + " if int(age) < 25:\n", + " print(name, age)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.9.13 64-bit", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}