2025 0415 update
| 
						 | 
				
			
			@ -18,7 +18,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 1,
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "id": "e9a8883a",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -26,22 +26,22 @@
 | 
			
		|||
     "name": "stdout",
 | 
			
		||||
     "output_type": "stream",
 | 
			
		||||
     "text": [
 | 
			
		||||
      "i = 1, i squared = 1\n",
 | 
			
		||||
      "i = 2, i squared = 4\n",
 | 
			
		||||
      "i = 3, i squared = 9\n",
 | 
			
		||||
      "i = 4, i squared = 16\n",
 | 
			
		||||
      "i = 5, i squared = 25\n"
 | 
			
		||||
      "Value = 1, Value squared = 1\n",
 | 
			
		||||
      "Value = 2, Value squared = 4\n",
 | 
			
		||||
      "Value = 3, Value squared = 9\n",
 | 
			
		||||
      "Value = 4, Value squared = 16\n",
 | 
			
		||||
      "Value = 5, Value squared = 25\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "for i in [1, 2, 3, 4, 5]:\n",
 | 
			
		||||
    "    print(f\"i = {i}, i squared = {i**2}\")"
 | 
			
		||||
    "for dummy in [1, 2, 3, 4, 5]:\n",
 | 
			
		||||
    "    print(f\"Value = {dummy}, Value squared = {dummy**2}\")"
 | 
			
		||||
   ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "execution_count": 4,
 | 
			
		||||
   "id": "ee7f5f12",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -60,7 +60,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 4,
 | 
			
		||||
   "execution_count": 5,
 | 
			
		||||
   "id": "2667d8d8",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -85,7 +85,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 4,
 | 
			
		||||
   "execution_count": 8,
 | 
			
		||||
   "id": "dd6ef6a6",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -133,6 +133,36 @@
 | 
			
		|||
    "for i in range(len(myLstVar1)):     # \"range(n)\" gives you series of numbers from 0 ... n-1\n",
 | 
			
		||||
    "    print(i, myLstVar1[i])"
 | 
			
		||||
   ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 13,
 | 
			
		||||
   "id": "52d35884-9507-485e-9637-25d7201ee6ff",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
     "output_type": "stream",
 | 
			
		||||
     "text": [
 | 
			
		||||
      "unsorted myLstVar1 contains  7  items. ['Blue', 'Green', 'Indigo', 'Orange', 'Red', 'Violet', 'Yellow']\n",
 | 
			
		||||
      "sorted myLstVar1 contains    7  items. ['Blue', 'Green', 'Indigo', 'Orange', 'Red', 'Violet', 'Yellow']\n",
 | 
			
		||||
      "0 Blue\n",
 | 
			
		||||
      "1 Green\n",
 | 
			
		||||
      "2 Indigo\n",
 | 
			
		||||
      "3 Orange\n",
 | 
			
		||||
      "4 Red\n",
 | 
			
		||||
      "5 Violet\n",
 | 
			
		||||
      "6 Yellow\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "print(\"unsorted myLstVar1 contains \", len(myLstVar1), \" items.\",myLstVar1)\n",
 | 
			
		||||
    "myLstVar1.sort()\n",
 | 
			
		||||
    "print(\"sorted myLstVar1 contains   \", len(myLstVar1), \" items.\",myLstVar1)\n",
 | 
			
		||||
    "for i in range(len(myLstVar1)):     # \"range(n)\" gives you series of numbers from 0 ... n-1\n",
 | 
			
		||||
    "    print(i, myLstVar1[i])"
 | 
			
		||||
   ]
 | 
			
		||||
  }
 | 
			
		||||
 ],
 | 
			
		||||
 "metadata": {
 | 
			
		||||
| 
						 | 
				
			
			@ -151,7 +181,7 @@
 | 
			
		|||
   "name": "python",
 | 
			
		||||
   "nbconvert_exporter": "python",
 | 
			
		||||
   "pygments_lexer": "ipython3",
 | 
			
		||||
   "version": "3.11.5"
 | 
			
		||||
   "version": "3.12.7"
 | 
			
		||||
  }
 | 
			
		||||
 },
 | 
			
		||||
 "nbformat": 4,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,14 +2,18 @@
 | 
			
		|||
 "cells": [
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "execution_count": 1,
 | 
			
		||||
   "id": "ae280d81",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "metadata": {
 | 
			
		||||
    "jupyter": {
 | 
			
		||||
     "source_hidden": true
 | 
			
		||||
    }
 | 
			
		||||
   },
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "# CSE-160-D01_2024FA_Tuple-Backgrounder\n",
 | 
			
		||||
    "#\n",
 | 
			
		||||
    "# A tuple is type of Python variable that can holdan ordered collection\n",
 | 
			
		||||
    "# A tuple is type of Python variable that can hold an ordered collection\n",
 | 
			
		||||
    "# of mutiple values of possibly differing data type, possibly duplicated\n",
 | 
			
		||||
    "# values and are used for information that should not be changed.\n",
 | 
			
		||||
    "#\n",
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +34,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 8,
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "id": "987287d1",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +52,8 @@
 | 
			
		|||
      "avgDiameterOfEarthInMiles type and length:  <class 'tuple'> 1 \n",
 | 
			
		||||
      "\n",
 | 
			
		||||
      "lockCombination =  ('right24', 'left31', 'right10')\n",
 | 
			
		||||
      "lockCombination type and length:  <class 'tuple'> 3\n"
 | 
			
		||||
      "lockCombination type and length:  <class 'tuple'> 3\n",
 | 
			
		||||
      "\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +81,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 14,
 | 
			
		||||
   "execution_count": 3,
 | 
			
		||||
   "id": "cc74b5b1",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -129,7 +134,7 @@
 | 
			
		|||
   "name": "python",
 | 
			
		||||
   "nbconvert_exporter": "python",
 | 
			
		||||
   "pygments_lexer": "ipython3",
 | 
			
		||||
   "version": "3.11.5"
 | 
			
		||||
   "version": "3.12.7"
 | 
			
		||||
  }
 | 
			
		||||
 },
 | 
			
		||||
 "nbformat": 4,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "execution_count": 1,
 | 
			
		||||
   "id": "d20dcd5f",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +43,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 3,
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "id": "564c0014",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -57,11 +57,11 @@
 | 
			
		|||
      "|        3.141592653589793|\n",
 | 
			
		||||
      "|    3.141592653589793    |\n",
 | 
			
		||||
      "\n",
 | 
			
		||||
      "Using String variable = 'Python 3.11.5'\n",
 | 
			
		||||
      "|Python 3.11.5            |\n",
 | 
			
		||||
      "|Python 3.11.5            |\n",
 | 
			
		||||
      "|            Python 3.11.5|\n",
 | 
			
		||||
      "|      Python 3.11.5      |\n"
 | 
			
		||||
      "Using String variable = 'Python 3.12.7'\n",
 | 
			
		||||
      "|Python 3.12.7            |\n",
 | 
			
		||||
      "|Python 3.12.7            |\n",
 | 
			
		||||
      "|            Python 3.12.7|\n",
 | 
			
		||||
      "|      Python 3.12.7      |\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
| 
						 | 
				
			
			@ -92,7 +92,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 13,
 | 
			
		||||
   "execution_count": 3,
 | 
			
		||||
   "id": "9f9b8587",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
| 
						 | 
				
			
			@ -105,10 +105,10 @@
 | 
			
		|||
      "|========3.141592653589793|\n",
 | 
			
		||||
      "|====3.141592653589793====|\n",
 | 
			
		||||
      "\n",
 | 
			
		||||
      "Using String variable = 'Python 3.11.5'\n",
 | 
			
		||||
      "|Python 3.11.5============|\n",
 | 
			
		||||
      "|============Python 3.11.5|\n",
 | 
			
		||||
      "|======Python 3.11.5======|\n"
 | 
			
		||||
      "Using String variable = 'Python 3.12.7'\n",
 | 
			
		||||
      "|Python 3.12.7============|\n",
 | 
			
		||||
      "|============Python 3.12.7|\n",
 | 
			
		||||
      "|======Python 3.12.7======|\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
| 
						 | 
				
			
			@ -131,9 +131,11 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 15,
 | 
			
		||||
   "execution_count": 6,
 | 
			
		||||
   "id": "deee1957",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "metadata": {
 | 
			
		||||
    "scrolled": true
 | 
			
		||||
   },
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
| 
						 | 
				
			
			@ -197,9 +199,13 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 16,
 | 
			
		||||
   "execution_count": 5,
 | 
			
		||||
   "id": "2a3efefd",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "metadata": {
 | 
			
		||||
    "jupyter": {
 | 
			
		||||
     "source_hidden": true
 | 
			
		||||
    }
 | 
			
		||||
   },
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +232,7 @@
 | 
			
		|||
    "\n",
 | 
			
		||||
    "variable *= -1 \n",
 | 
			
		||||
    "print(f\"Using Numeric {variable = }\") \n",
 | 
			
		||||
    "print(f\"With two decimal places and a comma: {variable:,.2f}\") "
 | 
			
		||||
    "print(f\"With two decimal places and a comma: {variable:,.4f}\") "
 | 
			
		||||
   ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			@ -266,28 +272,10 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 8,
 | 
			
		||||
   "execution_count": null,
 | 
			
		||||
   "id": "28b43c9c",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
     "output_type": "stream",
 | 
			
		||||
     "text": [
 | 
			
		||||
      "Number\t\t\tSquare\t\t\tCube\n",
 | 
			
		||||
      " 1\t\t\t  1\t\t\t   1\n",
 | 
			
		||||
      " 2\t\t\t  4\t\t\t   8\n",
 | 
			
		||||
      " 3\t\t\t  9\t\t\t  27\n",
 | 
			
		||||
      " 4\t\t\t 16\t\t\t  64\n",
 | 
			
		||||
      " 5\t\t\t 25\t\t\t 125\n",
 | 
			
		||||
      " 6\t\t\t 36\t\t\t 216\n",
 | 
			
		||||
      " 7\t\t\t 49\t\t\t 343\n",
 | 
			
		||||
      " 8\t\t\t 64\t\t\t 512\n",
 | 
			
		||||
      " 9\t\t\t 81\t\t\t 729\n",
 | 
			
		||||
      "10\t\t\t100\t\t\t1000\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "# The tab character (\\t) can also be used in an f-string to line up columns, \n",
 | 
			
		||||
    "# particularly when column headings are used: \n",
 | 
			
		||||
| 
						 | 
				
			
			@ -298,28 +286,10 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 9,
 | 
			
		||||
   "execution_count": null,
 | 
			
		||||
   "id": "de6c45f8",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
     "output_type": "stream",
 | 
			
		||||
     "text": [
 | 
			
		||||
      "Number\t\tSquare\t\tCube\n",
 | 
			
		||||
      " 1.00\t\t  1.00\t\t    1.00\n",
 | 
			
		||||
      " 2.00\t\t  4.00\t\t    8.00\n",
 | 
			
		||||
      " 3.00\t\t  9.00\t\t   27.00\n",
 | 
			
		||||
      " 4.00\t\t 16.00\t\t   64.00\n",
 | 
			
		||||
      " 5.00\t\t 25.00\t\t  125.00\n",
 | 
			
		||||
      " 6.00\t\t 36.00\t\t  216.00\n",
 | 
			
		||||
      " 7.00\t\t 49.00\t\t  343.00\n",
 | 
			
		||||
      " 8.00\t\t 64.00\t\t  512.00\n",
 | 
			
		||||
      " 9.00\t\t 81.00\t\t  729.00\n",
 | 
			
		||||
      "10.00\t\t100.00\t\t 1000.00\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "# Using either tabs or spacing is acceptable and may depend on which one you are more comfortable with. \n",
 | 
			
		||||
    "# Either way is acceptable in Python. \n",
 | 
			
		||||
| 
						 | 
				
			
			@ -333,23 +303,10 @@
 | 
			
		|||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 10,
 | 
			
		||||
   "execution_count": null,
 | 
			
		||||
   "id": "47fcbb2b",
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
     "output_type": "stream",
 | 
			
		||||
     "text": [
 | 
			
		||||
      "       My Grocery List        \n",
 | 
			
		||||
      "==============================\n",
 | 
			
		||||
      "Apples             3\t$ 1.50\n",
 | 
			
		||||
      "Rye Bread         10\t$15.00\n",
 | 
			
		||||
      "Cheese             6\t$13.50\n",
 | 
			
		||||
      "              Total:\t$30.00\n"
 | 
			
		||||
     ]
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "# This also demonstrates how the use of a value for width will enable the columns to line up. \n",
 | 
			
		||||
    "# The following program demonstrates the use of strings, decimals, and floats, as well as tabs \n",
 | 
			
		||||
| 
						 | 
				
			
			@ -406,7 +363,7 @@
 | 
			
		|||
   "name": "python",
 | 
			
		||||
   "nbconvert_exporter": "python",
 | 
			
		||||
   "pygments_lexer": "ipython3",
 | 
			
		||||
   "version": "3.11.5"
 | 
			
		||||
   "version": "3.12.7"
 | 
			
		||||
  }
 | 
			
		||||
 },
 | 
			
		||||
 "nbformat": 4,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250325/0 main page.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 46 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250325/1 Phone type.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 60 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250325/2 email address.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 55 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250325/3 Address.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 61 KiB  | 
							
								
								
									
										21
									
								
								bigos/lecture20250325/listvsdictionary.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
 | 
			
		||||
from pprint import pprint
 | 
			
		||||
 | 
			
		||||
addressList = ["John Smith", "1 Main St", "Anycity", "Ma", "01102"]
 | 
			
		||||
 | 
			
		||||
print(addressList)
 | 
			
		||||
 | 
			
		||||
print(sorted(addressList))
 | 
			
		||||
 | 
			
		||||
addressDictionary = {'Name':"John Smith", 'Address':"1 Main St", 'City': "Anycity",
 | 
			
		||||
                     'State':"Ma", 'ZipCode': "01102"}
 | 
			
		||||
 | 
			
		||||
print(addressDictionary)
 | 
			
		||||
 | 
			
		||||
print(addressDictionary.keys())
 | 
			
		||||
print(addressDictionary.values())
 | 
			
		||||
 | 
			
		||||
for Item in addressDictionary.keys():
 | 
			
		||||
    print(f"{Item:10s} {addressDictionary[Item]}")
 | 
			
		||||
 | 
			
		||||
pprint(addressDictionary)
 | 
			
		||||
							
								
								
									
										170
									
								
								bigos/lecture20250408/csvPandas/data.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,170 @@
 | 
			
		|||
Duration,Pulse,Maxpulse,Calories
 | 
			
		||||
60,110,130,409.1
 | 
			
		||||
60,117,145,479.0
 | 
			
		||||
60,103,135,340.0
 | 
			
		||||
45,109,175,282.4
 | 
			
		||||
45,117,148,406.0
 | 
			
		||||
60,102,127,300.5
 | 
			
		||||
60,110,136,374.0
 | 
			
		||||
45,104,134,253.3
 | 
			
		||||
30,109,133,195.1
 | 
			
		||||
60,98,124,269.0
 | 
			
		||||
60,103,147,329.3
 | 
			
		||||
60,100,120,250.7
 | 
			
		||||
60,106,128,345.3
 | 
			
		||||
60,104,132,379.3
 | 
			
		||||
60,98,123,275.0
 | 
			
		||||
60,98,120,215.2
 | 
			
		||||
60,100,120,300.0
 | 
			
		||||
45,90,112,
 | 
			
		||||
60,103,123,323.0
 | 
			
		||||
45,97,125,243.0
 | 
			
		||||
60,108,131,364.2
 | 
			
		||||
45,100,119,282.0
 | 
			
		||||
60,130,101,300.0
 | 
			
		||||
45,105,132,246.0
 | 
			
		||||
60,102,126,334.5
 | 
			
		||||
60,100,120,250.0
 | 
			
		||||
60,92,118,241.0
 | 
			
		||||
60,103,132
 | 
			
		||||
60,100,132,280.0
 | 
			
		||||
60,102,129,380.3
 | 
			
		||||
60,92,115,243.0
 | 
			
		||||
45,90,112,180.1
 | 
			
		||||
60,101,124,299.0
 | 
			
		||||
60,93,113,223.0
 | 
			
		||||
60,107,136,361.0
 | 
			
		||||
60,114,140,415.0
 | 
			
		||||
60,102,127,300.5
 | 
			
		||||
60,100,120,300.1
 | 
			
		||||
60,100,120,300.0
 | 
			
		||||
45,104,129,266.0
 | 
			
		||||
45,90,112,180.1
 | 
			
		||||
60,98,126,286.0
 | 
			
		||||
60,100,122,329.4
 | 
			
		||||
60,111,138,400.0
 | 
			
		||||
60,111,131,397.0
 | 
			
		||||
60,99,119,273.0
 | 
			
		||||
60,109,153,387.6
 | 
			
		||||
45,111,136,300.0
 | 
			
		||||
45,108,129,298.0
 | 
			
		||||
60,111,139,397.6
 | 
			
		||||
60,107,136,380.2
 | 
			
		||||
80,123,146,643.1
 | 
			
		||||
60,106,130,263.0
 | 
			
		||||
60,118,151,486.0
 | 
			
		||||
30,136,175,238.0
 | 
			
		||||
60,121,146,450.7
 | 
			
		||||
60,118,121,413.0
 | 
			
		||||
45,115,144,305.0
 | 
			
		||||
20,153,172,226.4
 | 
			
		||||
45,123,152,321.0
 | 
			
		||||
210,108,160,1376.0
 | 
			
		||||
160,110,137,1034.4
 | 
			
		||||
160,109,135,853.0
 | 
			
		||||
45,118,141,341.0
 | 
			
		||||
20,110,130,131.4
 | 
			
		||||
180,90,130,800.4
 | 
			
		||||
150,105,135,873.4
 | 
			
		||||
150,107,130,816.0
 | 
			
		||||
20,106,136,110.4
 | 
			
		||||
300,108,143,1500.2
 | 
			
		||||
150,97,129,1115.0
 | 
			
		||||
60,109,153,387.6
 | 
			
		||||
90,100,127,700.0
 | 
			
		||||
150,97,127,953.2
 | 
			
		||||
45,114,146,304.0
 | 
			
		||||
90,98,125,563.2
 | 
			
		||||
45,105,134,251.0
 | 
			
		||||
45,110,141,300.0
 | 
			
		||||
120,100,130,500.4
 | 
			
		||||
270,100,131,1729.0
 | 
			
		||||
30,159,182,319.2
 | 
			
		||||
45,149,169,344.0
 | 
			
		||||
30,103,139,151.1
 | 
			
		||||
120,100,130,500.0
 | 
			
		||||
45,100,120,225.3
 | 
			
		||||
30,151,170,300.1
 | 
			
		||||
45,102,136,234.0
 | 
			
		||||
120,100,157,1000.1
 | 
			
		||||
45,129,103,242.0
 | 
			
		||||
20,83,107,50.3
 | 
			
		||||
180,101,127,600.1
 | 
			
		||||
45,107,137,
 | 
			
		||||
30,90,107,105.3
 | 
			
		||||
15,80,100,50.5
 | 
			
		||||
20,150,171,127.4
 | 
			
		||||
20,151,168,229.4
 | 
			
		||||
30,95,128,128.2
 | 
			
		||||
25,152,168,244.2
 | 
			
		||||
30,109,131,188.2
 | 
			
		||||
90,93,124,604.1
 | 
			
		||||
20,95,112,77.7
 | 
			
		||||
90,90,110,500.0
 | 
			
		||||
90,90,100,500.0
 | 
			
		||||
90,90,100,500.4
 | 
			
		||||
30,92,108,92.7
 | 
			
		||||
30,93,128,124.0
 | 
			
		||||
180,90,120,800.3
 | 
			
		||||
30,90,120,86.2
 | 
			
		||||
90,90,120,500.3
 | 
			
		||||
210,137,184,1860.4
 | 
			
		||||
60,102,124,325.2
 | 
			
		||||
45,107,124,275.0
 | 
			
		||||
15,124,139,124.2
 | 
			
		||||
45,100,120,225.3
 | 
			
		||||
60,108,131,367.6
 | 
			
		||||
60,108,151,351.7
 | 
			
		||||
60,116,141,443.0
 | 
			
		||||
60,97,122,277.4
 | 
			
		||||
60,105,125,
 | 
			
		||||
60,103,124,332.7
 | 
			
		||||
30,112,137,193.9
 | 
			
		||||
45,100,120,100.7
 | 
			
		||||
60,119,169,336.7
 | 
			
		||||
60,107,127,344.9
 | 
			
		||||
60,111,151,368.5
 | 
			
		||||
60,98,122,271.0
 | 
			
		||||
60,97,124,275.3
 | 
			
		||||
60,109,127,382.0
 | 
			
		||||
90,99,125,466.4
 | 
			
		||||
60,114,151,384.0
 | 
			
		||||
60,104,134,342.5
 | 
			
		||||
60,107,138,357.5
 | 
			
		||||
60,103,133,335.0
 | 
			
		||||
60,106,132,327.5
 | 
			
		||||
60,103,136,339.0
 | 
			
		||||
20,136,156,189.0
 | 
			
		||||
45,117,143,317.7
 | 
			
		||||
45,115,137,318.0
 | 
			
		||||
45,113,138,308.0
 | 
			
		||||
20,141,162,222.4
 | 
			
		||||
60,108,135,390.0
 | 
			
		||||
60,97,127,
 | 
			
		||||
45,100,120,250.4
 | 
			
		||||
45,122,149,335.4
 | 
			
		||||
60,136,170,470.2
 | 
			
		||||
45,106,126,270.8
 | 
			
		||||
60,107,136,400.0
 | 
			
		||||
60,112,146,361.9
 | 
			
		||||
30,103,127,185.0
 | 
			
		||||
60,110,150,409.4
 | 
			
		||||
60,106,134,343.0
 | 
			
		||||
60,109,129,353.2
 | 
			
		||||
60,109,138,374.0
 | 
			
		||||
30,150,167,275.8
 | 
			
		||||
60,105,128,328.0
 | 
			
		||||
60,111,151,368.5
 | 
			
		||||
60,97,131,270.4
 | 
			
		||||
60,100,120,270.4
 | 
			
		||||
60,114,150,382.8
 | 
			
		||||
30,80,120,240.9
 | 
			
		||||
30,85,120,250.4
 | 
			
		||||
45,90,130,260.4
 | 
			
		||||
45,95,130,270.0
 | 
			
		||||
45,100,140,280.9
 | 
			
		||||
60,105,140,290.8
 | 
			
		||||
60,110,145,300.4
 | 
			
		||||
60,115,145,310.2
 | 
			
		||||
75,120,150,320.4
 | 
			
		||||
75,125,150,330.4
 | 
			
		||||
| 
		
		
			 Can't render this file because it has a wrong number of fields in line 29. 
		
	 | 
							
								
								
									
										8
									
								
								bigos/lecture20250408/csvPandas/dogs.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
DogName,BirthYear,Breed,Color
 | 
			
		||||
Harry,2007,Chinook,Buff
 | 
			
		||||
Shenanigans,2008,Chinook,Tawney
 | 
			
		||||
Mandy,2016,Chinook,Tawney
 | 
			
		||||
Tanner,2002,Golden Retriever,Tan
 | 
			
		||||
Rusty,2004,Golden Retriever,Tan
 | 
			
		||||
Gimli,2022,Chinook,Tawney
 | 
			
		||||
Yukon Jack,2020,Chinook,Tawney
 | 
			
		||||
		
		
			
  | 
							
								
								
									
										7
									
								
								bigos/lecture20250408/csvPandas/pandasreadcsv01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
# https://www.w3schools.com/python/pandas/pandas_csv.asp
 | 
			
		||||
 | 
			
		||||
import pandas as pd
 | 
			
		||||
 | 
			
		||||
df = pd.read_csv('data.csv')
 | 
			
		||||
 | 
			
		||||
print(df.to_string()) 
 | 
			
		||||
							
								
								
									
										7
									
								
								bigos/lecture20250408/csvPandas/pandasreadcsv01dogs.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
# https://www.w3schools.com/python/pandas/pandas_csv.asp
 | 
			
		||||
 | 
			
		||||
import pandas as pd
 | 
			
		||||
 | 
			
		||||
df = pd.read_csv('dogs.csv')
 | 
			
		||||
 | 
			
		||||
print(df.to_string()) 
 | 
			
		||||
							
								
								
									
										9
									
								
								bigos/lecture20250408/csvPandas/pandasreadcsv02.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
# https://www.w3schools.com/python/pandas/pandas_csv.asp
 | 
			
		||||
 | 
			
		||||
import pandas as pd
 | 
			
		||||
 | 
			
		||||
df = pd.read_csv('data.csv')
 | 
			
		||||
 | 
			
		||||
print(df.head())
 | 
			
		||||
 | 
			
		||||
print(df.tail())
 | 
			
		||||
							
								
								
									
										35
									
								
								bigos/lecture20250408/csvfiles/csvline1.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
 | 
			
		||||
line = "7/5/2016,123,638.5"
 | 
			
		||||
 | 
			
		||||
# split line on commas
 | 
			
		||||
lineFields = line.split(',')
 | 
			
		||||
 | 
			
		||||
print(lineFields)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Individual columns from the spreadsheet
 | 
			
		||||
print(lineFields[0], type(lineFields[0]) )
 | 
			
		||||
print(lineFields[1], type(lineFields[1]) )
 | 
			
		||||
print(lineFields[2], type(lineFields[2]) )
 | 
			
		||||
 | 
			
		||||
# Convert ISO date --> 20161115 or 2016-1115 or 2016-11-15
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
dateFields = lineFields[0].split('/')
 | 
			
		||||
print(dateFields)
 | 
			
		||||
 | 
			
		||||
#print(len(dateFields[0]))
 | 
			
		||||
#print(len(dateFields[1]))
 | 
			
		||||
 | 
			
		||||
if(len(dateFields[0]) == 1):
 | 
			
		||||
    dateFields[0] = "0"+ dateFields[0]
 | 
			
		||||
 | 
			
		||||
if(len(dateFields[1]) == 1):
 | 
			
		||||
    dateFields[1] = "0"+ dateFields[1]
 | 
			
		||||
 | 
			
		||||
print(dateFields)
 | 
			
		||||
 | 
			
		||||
isoDate = dateFields[2] + dateFields[0] + dateFields[1]
 | 
			
		||||
 | 
			
		||||
print("ISO Date = ", isoDate)
 | 
			
		||||
							
								
								
									
										11
									
								
								bigos/lecture20250408/csvfiles/csvline2.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
# Read a csv file from the current directory
 | 
			
		||||
# import the csv function library
 | 
			
		||||
import csv
 | 
			
		||||
 | 
			
		||||
filename = "dogs.csv"
 | 
			
		||||
 | 
			
		||||
with open(filename,'r') as csvfile:
 | 
			
		||||
    csvData = csv.reader(csvfile,delimiter = ',',quotechar = '"')
 | 
			
		||||
    for row in csvData:
 | 
			
		||||
        print(row)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								bigos/lecture20250408/csvfiles/csvweather1.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
 | 
			
		||||
dataHeaders = "id,value,feed_id,created_at,lat,lon,ele"
 | 
			
		||||
 | 
			
		||||
dataValues = "0FV1TKJ51XRHX03W57F3PVC7K8,77.2,2756158,2025-03-17 18:16:42 UTC,,,"
 | 
			
		||||
 | 
			
		||||
print(dataHeaders)
 | 
			
		||||
 | 
			
		||||
headerFields = dataHeaders.split(",")
 | 
			
		||||
print(headerFields)
 | 
			
		||||
 | 
			
		||||
print(dataValues)
 | 
			
		||||
valuesFields = dataValues.split(",")
 | 
			
		||||
print(valuesFields)
 | 
			
		||||
 | 
			
		||||
myFields = [valuesFields[3],valuesFields[1]]
 | 
			
		||||
 | 
			
		||||
print(myFields)
 | 
			
		||||
							
								
								
									
										170
									
								
								bigos/lecture20250408/csvfiles/data.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,170 @@
 | 
			
		|||
Duration,Pulse,Maxpulse,Calories
 | 
			
		||||
60,110,130,409.1
 | 
			
		||||
60,117,145,479.0
 | 
			
		||||
60,103,135,340.0
 | 
			
		||||
45,109,175,282.4
 | 
			
		||||
45,117,148,406.0
 | 
			
		||||
60,102,127,300.5
 | 
			
		||||
60,110,136,374.0
 | 
			
		||||
45,104,134,253.3
 | 
			
		||||
30,109,133,195.1
 | 
			
		||||
60,98,124,269.0
 | 
			
		||||
60,103,147,329.3
 | 
			
		||||
60,100,120,250.7
 | 
			
		||||
60,106,128,345.3
 | 
			
		||||
60,104,132,379.3
 | 
			
		||||
60,98,123,275.0
 | 
			
		||||
60,98,120,215.2
 | 
			
		||||
60,100,120,300.0
 | 
			
		||||
45,90,112,
 | 
			
		||||
60,103,123,323.0
 | 
			
		||||
45,97,125,243.0
 | 
			
		||||
60,108,131,364.2
 | 
			
		||||
45,100,119,282.0
 | 
			
		||||
60,130,101,300.0
 | 
			
		||||
45,105,132,246.0
 | 
			
		||||
60,102,126,334.5
 | 
			
		||||
60,100,120,250.0
 | 
			
		||||
60,92,118,241.0
 | 
			
		||||
60,103,132
 | 
			
		||||
60,100,132,280.0
 | 
			
		||||
60,102,129,380.3
 | 
			
		||||
60,92,115,243.0
 | 
			
		||||
45,90,112,180.1
 | 
			
		||||
60,101,124,299.0
 | 
			
		||||
60,93,113,223.0
 | 
			
		||||
60,107,136,361.0
 | 
			
		||||
60,114,140,415.0
 | 
			
		||||
60,102,127,300.5
 | 
			
		||||
60,100,120,300.1
 | 
			
		||||
60,100,120,300.0
 | 
			
		||||
45,104,129,266.0
 | 
			
		||||
45,90,112,180.1
 | 
			
		||||
60,98,126,286.0
 | 
			
		||||
60,100,122,329.4
 | 
			
		||||
60,111,138,400.0
 | 
			
		||||
60,111,131,397.0
 | 
			
		||||
60,99,119,273.0
 | 
			
		||||
60,109,153,387.6
 | 
			
		||||
45,111,136,300.0
 | 
			
		||||
45,108,129,298.0
 | 
			
		||||
60,111,139,397.6
 | 
			
		||||
60,107,136,380.2
 | 
			
		||||
80,123,146,643.1
 | 
			
		||||
60,106,130,263.0
 | 
			
		||||
60,118,151,486.0
 | 
			
		||||
30,136,175,238.0
 | 
			
		||||
60,121,146,450.7
 | 
			
		||||
60,118,121,413.0
 | 
			
		||||
45,115,144,305.0
 | 
			
		||||
20,153,172,226.4
 | 
			
		||||
45,123,152,321.0
 | 
			
		||||
210,108,160,1376.0
 | 
			
		||||
160,110,137,1034.4
 | 
			
		||||
160,109,135,853.0
 | 
			
		||||
45,118,141,341.0
 | 
			
		||||
20,110,130,131.4
 | 
			
		||||
180,90,130,800.4
 | 
			
		||||
150,105,135,873.4
 | 
			
		||||
150,107,130,816.0
 | 
			
		||||
20,106,136,110.4
 | 
			
		||||
300,108,143,1500.2
 | 
			
		||||
150,97,129,1115.0
 | 
			
		||||
60,109,153,387.6
 | 
			
		||||
90,100,127,700.0
 | 
			
		||||
150,97,127,953.2
 | 
			
		||||
45,114,146,304.0
 | 
			
		||||
90,98,125,563.2
 | 
			
		||||
45,105,134,251.0
 | 
			
		||||
45,110,141,300.0
 | 
			
		||||
120,100,130,500.4
 | 
			
		||||
270,100,131,1729.0
 | 
			
		||||
30,159,182,319.2
 | 
			
		||||
45,149,169,344.0
 | 
			
		||||
30,103,139,151.1
 | 
			
		||||
120,100,130,500.0
 | 
			
		||||
45,100,120,225.3
 | 
			
		||||
30,151,170,300.1
 | 
			
		||||
45,102,136,234.0
 | 
			
		||||
120,100,157,1000.1
 | 
			
		||||
45,129,103,242.0
 | 
			
		||||
20,83,107,50.3
 | 
			
		||||
180,101,127,600.1
 | 
			
		||||
45,107,137,
 | 
			
		||||
30,90,107,105.3
 | 
			
		||||
15,80,100,50.5
 | 
			
		||||
20,150,171,127.4
 | 
			
		||||
20,151,168,229.4
 | 
			
		||||
30,95,128,128.2
 | 
			
		||||
25,152,168,244.2
 | 
			
		||||
30,109,131,188.2
 | 
			
		||||
90,93,124,604.1
 | 
			
		||||
20,95,112,77.7
 | 
			
		||||
90,90,110,500.0
 | 
			
		||||
90,90,100,500.0
 | 
			
		||||
90,90,100,500.4
 | 
			
		||||
30,92,108,92.7
 | 
			
		||||
30,93,128,124.0
 | 
			
		||||
180,90,120,800.3
 | 
			
		||||
30,90,120,86.2
 | 
			
		||||
90,90,120,500.3
 | 
			
		||||
210,137,184,1860.4
 | 
			
		||||
60,102,124,325.2
 | 
			
		||||
45,107,124,275.0
 | 
			
		||||
15,124,139,124.2
 | 
			
		||||
45,100,120,225.3
 | 
			
		||||
60,108,131,367.6
 | 
			
		||||
60,108,151,351.7
 | 
			
		||||
60,116,141,443.0
 | 
			
		||||
60,97,122,277.4
 | 
			
		||||
60,105,125,
 | 
			
		||||
60,103,124,332.7
 | 
			
		||||
30,112,137,193.9
 | 
			
		||||
45,100,120,100.7
 | 
			
		||||
60,119,169,336.7
 | 
			
		||||
60,107,127,344.9
 | 
			
		||||
60,111,151,368.5
 | 
			
		||||
60,98,122,271.0
 | 
			
		||||
60,97,124,275.3
 | 
			
		||||
60,109,127,382.0
 | 
			
		||||
90,99,125,466.4
 | 
			
		||||
60,114,151,384.0
 | 
			
		||||
60,104,134,342.5
 | 
			
		||||
60,107,138,357.5
 | 
			
		||||
60,103,133,335.0
 | 
			
		||||
60,106,132,327.5
 | 
			
		||||
60,103,136,339.0
 | 
			
		||||
20,136,156,189.0
 | 
			
		||||
45,117,143,317.7
 | 
			
		||||
45,115,137,318.0
 | 
			
		||||
45,113,138,308.0
 | 
			
		||||
20,141,162,222.4
 | 
			
		||||
60,108,135,390.0
 | 
			
		||||
60,97,127,
 | 
			
		||||
45,100,120,250.4
 | 
			
		||||
45,122,149,335.4
 | 
			
		||||
60,136,170,470.2
 | 
			
		||||
45,106,126,270.8
 | 
			
		||||
60,107,136,400.0
 | 
			
		||||
60,112,146,361.9
 | 
			
		||||
30,103,127,185.0
 | 
			
		||||
60,110,150,409.4
 | 
			
		||||
60,106,134,343.0
 | 
			
		||||
60,109,129,353.2
 | 
			
		||||
60,109,138,374.0
 | 
			
		||||
30,150,167,275.8
 | 
			
		||||
60,105,128,328.0
 | 
			
		||||
60,111,151,368.5
 | 
			
		||||
60,97,131,270.4
 | 
			
		||||
60,100,120,270.4
 | 
			
		||||
60,114,150,382.8
 | 
			
		||||
30,80,120,240.9
 | 
			
		||||
30,85,120,250.4
 | 
			
		||||
45,90,130,260.4
 | 
			
		||||
45,95,130,270.0
 | 
			
		||||
45,100,140,280.9
 | 
			
		||||
60,105,140,290.8
 | 
			
		||||
60,110,145,300.4
 | 
			
		||||
60,115,145,310.2
 | 
			
		||||
75,120,150,320.4
 | 
			
		||||
75,125,150,330.4
 | 
			
		||||
| 
		
		
			 Can't render this file because it has a wrong number of fields in line 29. 
		
	 | 
							
								
								
									
										3
									
								
								bigos/lecture20250408/csvfiles/demofile.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
Hello! Welcome to demofile.txt
 | 
			
		||||
This file is for testing purposes.
 | 
			
		||||
Good Luck!
 | 
			
		||||
							
								
								
									
										8
									
								
								bigos/lecture20250408/csvfiles/dogs-with-hidden-char.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
DogName,BirthYear,Breed,Color
 | 
			
		||||
Harry,2007,Chinook,Buff
 | 
			
		||||
Shenanigans,2008,Chinook,Tawney
 | 
			
		||||
Mandy,2016,Chinook,Tawney
 | 
			
		||||
Tanner,2002,Golden Retriever,Tan
 | 
			
		||||
Rusty,2004,Golden Retriever,Tan
 | 
			
		||||
Gimli,2022,Chinook,Tawney
 | 
			
		||||
Yukon Jack,2020,Chinook,Tawney
 | 
			
		||||
		
		
			
  | 
							
								
								
									
										8
									
								
								bigos/lecture20250408/csvfiles/dogs.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
DogName,BirthYear,Breed,Color
 | 
			
		||||
Harry,2007,Chinook,Buff
 | 
			
		||||
Shenanigans,2008,Chinook,Tawney
 | 
			
		||||
Mandy,2016,Chinook,Tawney
 | 
			
		||||
Tanner,2002,Golden Retriever,Tan
 | 
			
		||||
Rusty,2004,Golden Retriever,Tan
 | 
			
		||||
Gimli,2022,Chinook,Tawney
 | 
			
		||||
Yukon Jack,2020,Chinook,Tawney
 | 
			
		||||
		
		
			
  | 
							
								
								
									
										5
									
								
								bigos/lecture20250408/csvfiles/fileread01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
# https://www.w3schools.com/python/python_file_open.asp
 | 
			
		||||
 | 
			
		||||
f = open("demofile.txt", "r")
 | 
			
		||||
 | 
			
		||||
print(f.read())
 | 
			
		||||
							
								
								
									
										9
									
								
								bigos/lecture20250408/csvfiles/filereadwrite01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
# https://www.w3schools.com/python/python_file_write.asp
 | 
			
		||||
 | 
			
		||||
f = open("demofile2.txt", "a")
 | 
			
		||||
f.write("Now the file has more content!")
 | 
			
		||||
f.close()
 | 
			
		||||
 | 
			
		||||
#open and read the file after the appending:
 | 
			
		||||
f = open("demofile2.txt", "r")
 | 
			
		||||
print(f.read())
 | 
			
		||||
							
								
								
									
										10
									
								
								bigos/lecture20250408/csvfiles/filereadwrite02.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,10 @@
 | 
			
		|||
# https://www.w3schools.com/python/python_file_write.asp
 | 
			
		||||
 | 
			
		||||
f = open("demofile3.txt", "w")
 | 
			
		||||
f.write("Woops! I have deleted the content!")
 | 
			
		||||
f.close()
 | 
			
		||||
 | 
			
		||||
#open and read the file after the overwriting:
 | 
			
		||||
f = open("demofile3.txt", "r")
 | 
			
		||||
print(f.read())
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										39
									
								
								bigos/lecture20250408/csvfiles/hidden-character-dump.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
 | 
			
		||||
This is from file dogs-with-hidden-char.csv
 | 
			
		||||
 | 
			
		||||
Sometimes hidden characters are exported from the spreadsheet program. Run csvline2.py
 | 
			
		||||
with the filename set to dogs-with-hidden-char.csv
 | 
			
		||||
 | 
			
		||||
(base) edbigos@Edwards-MacBook-Pro-4 csvlines % od -bc dogs-with-hidden-char.csv
 | 
			
		||||
0000000   357 273 277 104 157 147 116 141 155 145 054 102 151 162 164 150
 | 
			
		||||
         357 273 277   D   o   g   N   a   m   e   ,   B   i   r   t   h
 | 
			
		||||
0000020   131 145 141 162 054 102 162 145 145 144 054 103 157 154 157 162
 | 
			
		||||
           Y   e   a   r   ,   B   r   e   e   d   ,   C   o   l   o   r
 | 
			
		||||
0000040   015 012 110 141 162 162 171 054 062 060 060 067 054 103 150 151
 | 
			
		||||
          \r  \n   H   a   r   r   y   ,   2   0   0   7   ,   C   h   i
 | 
			
		||||
0000060   156 157 157 153 054 102 165 146 146 015 012 123 150 145 156 141
 | 
			
		||||
           n   o   o   k   ,   B   u   f   f  \r  \n   S   h   e   n   a
 | 
			
		||||
0000100   156 151 147 141 156 163 054 062 060 060 070 054 103 150 151 156
 | 
			
		||||
           n   i   g   a   n   s   ,   2   0   0   8   ,   C   h   i   n
 | 
			
		||||
0000120   157 157 153 054 124 141 167 156 145 171 015 012 115 141 156 144
 | 
			
		||||
           o   o   k   ,   T   a   w   n   e   y  \r  \n   M   a   n   d
 | 
			
		||||
0000140   171 054 062 060 061 066 054 103 150 151 156 157 157 153 054 124
 | 
			
		||||
           y   ,   2   0   1   6   ,   C   h   i   n   o   o   k   ,   T
 | 
			
		||||
0000160   141 167 156 145 171 015 012 124 141 156 156 145 162 054 062 060
 | 
			
		||||
           a   w   n   e   y  \r  \n   T   a   n   n   e   r   ,   2   0
 | 
			
		||||
0000200   060 062 054 107 157 154 144 145 156 040 122 145 164 162 151 145
 | 
			
		||||
           0   2   ,   G   o   l   d   e   n       R   e   t   r   i   e
 | 
			
		||||
0000220   166 145 162 054 124 141 156 015 012 122 165 163 164 171 054 062
 | 
			
		||||
           v   e   r   ,   T   a   n  \r  \n   R   u   s   t   y   ,   2
 | 
			
		||||
0000240   060 060 064 054 107 157 154 144 145 156 040 122 145 164 162 151
 | 
			
		||||
           0   0   4   ,   G   o   l   d   e   n       R   e   t   r   i
 | 
			
		||||
0000260   145 166 145 162 054 124 141 156 015 012 107 151 155 154 151 054
 | 
			
		||||
           e   v   e   r   ,   T   a   n  \r  \n   G   i   m   l   i   ,
 | 
			
		||||
0000300   062 060 062 062 054 103 150 151 156 157 157 153 054 124 141 167
 | 
			
		||||
           2   0   2   2   ,   C   h   i   n   o   o   k   ,   T   a   w
 | 
			
		||||
0000320   156 145 171 015 012 131 165 153 157 156 040 112 141 143 153 054
 | 
			
		||||
           n   e   y  \r  \n   Y   u   k   o   n       J   a   c   k   ,
 | 
			
		||||
0000340   062 060 062 060 054 103 150 151 156 157 157 153 054 124 141 167
 | 
			
		||||
           2   0   2   0   ,   C   h   i   n   o   o   k   ,   T   a   w
 | 
			
		||||
0000360   156 145 171
 | 
			
		||||
           n   e   y
 | 
			
		||||
							
								
								
									
										7
									
								
								bigos/lecture20250408/csvfiles/osFileRemove.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
# https://www.w3schools.com/python/python_file_remove.asp
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
if os.path.exists("demofile3.txt"):
 | 
			
		||||
  os.remove("demofile3.txt")
 | 
			
		||||
else:
 | 
			
		||||
  print("The file does not exist")
 | 
			
		||||
							
								
								
									
										6
									
								
								bigos/lecture20250408/csvfiles1/Book1.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
Date,Quan,Cost,Total
 | 
			
		||||
4/8/25,1,$1.00,$1.00
 | 
			
		||||
4/8/25,2,$0.97,$1.94
 | 
			
		||||
4/8/25,4,$45.00,$180.00
 | 
			
		||||
4/8/25,6,$12.00,$72.00
 | 
			
		||||
4/8/25,9,$11.00,$99.00
 | 
			
		||||
		
		
			
  | 
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250408/csvfiles1/Book1.xlsx
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										88799
									
								
								bigos/lecture20250408/fileio_census/all-last.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										7
									
								
								bigos/lecture20250408/fileio_census/census-data-info.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
The columns in the census data correspond to:
 | 
			
		||||
 | 
			
		||||
Column  Data
 | 
			
		||||
1       A "Name"
 | 
			
		||||
2       Frequency in percent
 | 
			
		||||
3       Cumulative Frequency in percent
 | 
			
		||||
4       Rank
 | 
			
		||||
							
								
								
									
										4275
									
								
								bigos/lecture20250408/fileio_census/female-first.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										4275
									
								
								bigos/lecture20250408/fileio_census/female-first.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										29
									
								
								bigos/lecture20250408/fileio_census/file-read01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
## ============================ One time initializations ========================
 | 
			
		||||
#fileName = "testdata.txt" # this generates an error
 | 
			
		||||
fileName = "female-first.txt"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## ============================ Open and process file(s) ========================
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    runFlag = True
 | 
			
		||||
    while(runFlag):            # Process while true
 | 
			
		||||
#        print(count,line.rstrip("\n"))
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        if line == "":
 | 
			
		||||
            runFlag == False
 | 
			
		||||
        else:
 | 
			
		||||
            line = line.rstrip("\n")
 | 
			
		||||
            print(count,line)
 | 
			
		||||
            count = count + 1
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										28
									
								
								bigos/lecture20250408/fileio_census/file-read02.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
## ============================ One time initializations ========================
 | 
			
		||||
fileName = "female-first.txt"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## ============================ Open and process file(s) ========================
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    runFlag = True
 | 
			
		||||
    while(runFlag):            # Process while true
 | 
			
		||||
#        print(count,line.rstrip("\n"))
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        if not (line == ""):
 | 
			
		||||
            line = line.rstrip("\n")
 | 
			
		||||
            print(count,line)
 | 
			
		||||
            count = count + 1
 | 
			
		||||
        else:
 | 
			
		||||
           runFlag == False
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										28
									
								
								bigos/lecture20250408/fileio_census/file-read03.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
## ============================ One time initializations ========================
 | 
			
		||||
fileName = "testdata.txt"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## ============================ Open and process file(s) ========================
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    runFlag = True
 | 
			
		||||
    while(1):            # Process while true
 | 
			
		||||
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        if line == "":              # Exit on empty line == end of file
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
        print(count,line)
 | 
			
		||||
        count = count + 1
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										35
									
								
								bigos/lecture20250408/fileio_census/file-read04.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
## ============================ One time initializations ========================
 | 
			
		||||
fileName = "female-first.txt"
 | 
			
		||||
outFileName = "female-first.csv"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## ============================ Open and process file(s) ========================
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
    outFile = open(outFileName,'w')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    runFlag = True
 | 
			
		||||
    while(1):            # Process while true
 | 
			
		||||
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        if line == "":              # Exit on empty line == end of file
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
        line = line.lstrip().rstrip()
 | 
			
		||||
        print(count,line)
 | 
			
		||||
        csvLine = re.sub(' +',',',line)
 | 
			
		||||
        print("\t",csvLine)
 | 
			
		||||
        outFile.write(csvLine + "\n")
 | 
			
		||||
        count = count + 1
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										25
									
								
								bigos/lecture20250408/fileio_census/fileread01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
# See https://stackabuse.com/read-a-file-line-by-line-in-python/
 | 
			
		||||
# for more information
 | 
			
		||||
# Just try reading it line by line on the first attempt.
 | 
			
		||||
 | 
			
		||||
fileName = "testdata.txt"
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    line = inFile.readline()
 | 
			
		||||
    line = line.rstrip("\n")
 | 
			
		||||
    while(line):  # Read line and place in variable named line
 | 
			
		||||
#        print(count,line.rstrip("\n"))
 | 
			
		||||
        print(count,line)
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
        count = count + 1
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										38
									
								
								bigos/lecture20250408/fileio_census/get-firstname.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
## ============================ One time initializations ========================
 | 
			
		||||
fileName = "female-first.txt"
 | 
			
		||||
 | 
			
		||||
nameToSearch = input("Enter a first name: ")
 | 
			
		||||
nameToSearch = nameToSearch.upper()
 | 
			
		||||
 | 
			
		||||
## ============================ Open and process file(s) ========================
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    runFlag = True
 | 
			
		||||
    while(1):            # Process while true
 | 
			
		||||
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        if line == "":              # Exit on empty line == end of file
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
#        print(count,line)
 | 
			
		||||
        fieldList = line.split(" ")
 | 
			
		||||
#        print(fieldList)
 | 
			
		||||
        print(fieldList[0],len(fieldList[0]))
 | 
			
		||||
 | 
			
		||||
        if nameToSearch == fieldList[0] :
 | 
			
		||||
            print("Matched {} = {} at position {}".format(nameToSearch,fieldList[0],count))
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
        count = count + 1
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										34
									
								
								bigos/lecture20250408/fileio_census/get-name-with-spaces.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
## ============================ One time initializations ========================
 | 
			
		||||
fileName = "female-first.txt"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## ============================ Open and process file(s) ========================
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(fileName,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    runFlag = True
 | 
			
		||||
    while(1):            # Process while true
 | 
			
		||||
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        if line == "":              # Exit on empty line == end of file
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
        print(count,line)
 | 
			
		||||
        line = line.replace("  "," ")
 | 
			
		||||
        print("\t",count,line)
 | 
			
		||||
        fieldList = line.split(" ")
 | 
			
		||||
        print(fieldList)
 | 
			
		||||
        for field in fieldList:
 | 
			
		||||
            print(field)
 | 
			
		||||
        count = count + 1
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("Some error occurred. Ending here")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
inFile.close()
 | 
			
		||||
							
								
								
									
										1219
									
								
								bigos/lecture20250408/fileio_census/male-first.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										8
									
								
								bigos/lecture20250408/fileio_dogs/dogs.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
DogName,BirthYear,Breed,Color
 | 
			
		||||
Harry,2007,Chinook,Buff
 | 
			
		||||
Shenanigans,2008,Chinook,Tawney
 | 
			
		||||
Mandy,2016,Chinook,Tawney
 | 
			
		||||
Tanner,2002,Golden Retriever,Tan
 | 
			
		||||
Rusty,2004,Golden Retriever,Tan
 | 
			
		||||
Gimli,2022,Chinook,Tawney
 | 
			
		||||
Yukon Jack,2020,Chinook,Tawney
 | 
			
		||||
		
		
			
  | 
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250408/fileio_dogs/dogs.xlsx
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										23
									
								
								bigos/lecture20250408/fileio_dogs/fileread01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# See https://stackabuse.com/read-a-file-line-by-line-in-python/
 | 
			
		||||
# for more information
 | 
			
		||||
# Just try reading it line by line on the first attempt.
 | 
			
		||||
filename = "testxdata.txt"
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open(filename,'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    line = inFile.readline()
 | 
			
		||||
    line = line.rstrip("\n")
 | 
			
		||||
    while(line):  # Read line and place in variable named line
 | 
			
		||||
#        print(count,line.rstrip("\n"))
 | 
			
		||||
        print(count,line)
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
        count = count + 1
 | 
			
		||||
except:
 | 
			
		||||
    print(f"The file {filename} cannot be accessed.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										29
									
								
								bigos/lecture20250408/fileio_dogs/fileread022.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
# See https://stackabuse.com/read-a-file-line-by-line-in-python/
 | 
			
		||||
# for more information
 | 
			
		||||
# Just try reading it line by line on the first attempt.
 | 
			
		||||
try:
 | 
			
		||||
    inFile = open("dogs.csv",'r')
 | 
			
		||||
 | 
			
		||||
    count = 1
 | 
			
		||||
    line = inFile.readline()
 | 
			
		||||
    line = line.rstrip("\n")
 | 
			
		||||
# process header
 | 
			
		||||
    columnNames = line.split(",")
 | 
			
		||||
    print(columnNames)
 | 
			
		||||
    while(line):  # Read line and place in variable named line
 | 
			
		||||
#        print(count,line.rstrip("\n"))
 | 
			
		||||
        print(count,line)
 | 
			
		||||
        columns = line.split(",")
 | 
			
		||||
#        print(columns)
 | 
			
		||||
        counter = 0
 | 
			
		||||
        while(counter < 4):
 | 
			
		||||
            print("\t{:12s} {:>20s}".format(columnNames[counter],columns[counter]) )
 | 
			
		||||
            counter = counter + 1
 | 
			
		||||
        line = inFile.readline()
 | 
			
		||||
        line = line.rstrip("\n")
 | 
			
		||||
        count = count + 1
 | 
			
		||||
 | 
			
		||||
finally:
 | 
			
		||||
    inFile.close()
 | 
			
		||||
							
								
								
									
										22
									
								
								bigos/lecture20250408/fileio_dogs/filewrite01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
# See https://stackabuse.com/read-a-file-line-by-line-in-python/
 | 
			
		||||
# for more information
 | 
			
		||||
# Just try reading it line by line on the first attempt.
 | 
			
		||||
 | 
			
		||||
sampleData = ["Harry", "Colorado", "Shenanigans", "Mandy", "Rusty"]
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    outFile = open("testdatawrite.txt",'w')
 | 
			
		||||
 | 
			
		||||
    for dog in sampleData:
 | 
			
		||||
        print(dog)
 | 
			
		||||
        outFile.writelines(dog+"\n")
 | 
			
		||||
 | 
			
		||||
except:
 | 
			
		||||
    print("File write error!")
 | 
			
		||||
    exit(-1)
 | 
			
		||||
 | 
			
		||||
# When I get to the end of the file.
 | 
			
		||||
#finally:
 | 
			
		||||
outFile.close()
 | 
			
		||||
							
								
								
									
										4
									
								
								bigos/lecture20250408/fileio_dogs/testdata.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
Harry,2007
 | 
			
		||||
Shenanigans,2010
 | 
			
		||||
Katrina,2005
 | 
			
		||||
Mandy,2016
 | 
			
		||||
							
								
								
									
										5
									
								
								bigos/lecture20250408/fileio_dogs/testdatawrite.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
Harry
 | 
			
		||||
Colorado
 | 
			
		||||
Shenanigans
 | 
			
		||||
Mandy
 | 
			
		||||
Rusty
 | 
			
		||||
							
								
								
									
										5
									
								
								bigos/lecture20250408/fileio_dogs/testxdata.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
Harry
 | 
			
		||||
Colorado
 | 
			
		||||
Shenanigans
 | 
			
		||||
Mandy
 | 
			
		||||
Rusty
 | 
			
		||||
							
								
								
									
										8
									
								
								bigos/lecture20250408/try/try01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
 | 
			
		||||
data1 = float(input("Enter the dividend "))
 | 
			
		||||
 | 
			
		||||
data2 = float(input("Enter the divisor "))
 | 
			
		||||
 | 
			
		||||
quotient = data1/data2
 | 
			
		||||
 | 
			
		||||
print(f"{data1}/{data2} = {quotient}")
 | 
			
		||||
							
								
								
									
										13
									
								
								bigos/lecture20250408/try/try02.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
import sys
 | 
			
		||||
 | 
			
		||||
data1 = float(input("Enter the dividend "))
 | 
			
		||||
 | 
			
		||||
data2 = float(input("Enter the divisor "))
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
	quotient = data1/data2
 | 
			
		||||
	print(f"{data1}/{data2} = {quotient}")
 | 
			
		||||
except:
 | 
			
		||||
	print(f"Invalid value. Division by zero is not allowed.")
 | 
			
		||||
	sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								bigos/lecture20250408/try/try03.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
import sys
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
	data1 = float(input("Enter the dividend "))
 | 
			
		||||
except:
 | 
			
		||||
	print(f"Invalid value for the dividend ")
 | 
			
		||||
	sys.exit(-2)
 | 
			
		||||
try:
 | 
			
		||||
	data2 = float(input("Enter the divisor "))
 | 
			
		||||
except:
 | 
			
		||||
	print(f"Invalid value for the divisor ")
 | 
			
		||||
	sys.exit(-3)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
	quotient = data1/data2
 | 
			
		||||
	print(f"{data1}/{data2} = {quotient}")
 | 
			
		||||
except:
 | 
			
		||||
	print(f"Invalid value. Division by zero is not allowed.")
 | 
			
		||||
	sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										19
									
								
								bigos/lecture20250408/try/try04.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
import sys
 | 
			
		||||
 | 
			
		||||
def getFloatValue(message):
 | 
			
		||||
	try:
 | 
			
		||||
		data1 = float(input(message))
 | 
			
		||||
	except:
 | 
			
		||||
		print(f"Invalid value for a floating point number. ")
 | 
			
		||||
		sys.exit(-2)
 | 
			
		||||
	return data1
 | 
			
		||||
 | 
			
		||||
data1 = getFloatValue("Enter value for the dividend ")
 | 
			
		||||
data2 = getFloatValue("Enter value for the divisor ")
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
	quotient = data1/data2
 | 
			
		||||
	print(f"{data1}/{data2} = {quotient}")
 | 
			
		||||
except:
 | 
			
		||||
	print(f"Invalid value. Division by zero is not allowed.")
 | 
			
		||||
	sys.exit(-1)
 | 
			
		||||
							
								
								
									
										4
									
								
								bigos/lecture20250408/z-links.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
# https://www.w3schools.io/file/csv-extension-introduction/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								bigos/lecture20250415/matplotlib/matplot01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
import matplotlib.pyplot as plt
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
plt.style.use('_mpl-gallery')
 | 
			
		||||
 | 
			
		||||
# Make data
 | 
			
		||||
n = 100
 | 
			
		||||
xs = np.linspace(0, 1, n)
 | 
			
		||||
ys = np.sin(xs * 6 * np.pi)
 | 
			
		||||
zs = np.cos(xs * 6 * np.pi)
 | 
			
		||||
 | 
			
		||||
# Plot
 | 
			
		||||
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
 | 
			
		||||
ax.plot(xs, ys, zs)
 | 
			
		||||
 | 
			
		||||
ax.set(xticklabels=[],
 | 
			
		||||
       yticklabels=[],
 | 
			
		||||
       zticklabels=[])
 | 
			
		||||
 | 
			
		||||
plt.show()
 | 
			
		||||
							
								
								
									
										24
									
								
								bigos/lecture20250415/matplotlib/matplot02.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
import matplotlib.pyplot as plt
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
plt.style.use('_mpl-gallery')
 | 
			
		||||
 | 
			
		||||
# make data
 | 
			
		||||
x = np.linspace(0, 10, 100)
 | 
			
		||||
y = 4 + 1 * np.sin(2 * x)
 | 
			
		||||
x2 = np.linspace(0, 10, 25)
 | 
			
		||||
y2 = 4 + 1 * np.sin(2 * x2)
 | 
			
		||||
 | 
			
		||||
print(x)
 | 
			
		||||
 | 
			
		||||
# plot
 | 
			
		||||
fig, ax = plt.subplots()
 | 
			
		||||
 | 
			
		||||
#ax.plot(x2, y2 + 2.5, 'x', markeredgewidth=2)
 | 
			
		||||
ax.plot(x, y, linewidth=2.0)
 | 
			
		||||
#ax.plot(x2, y2 - 2.5, 'o-', linewidth=2)
 | 
			
		||||
 | 
			
		||||
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
 | 
			
		||||
       ylim=(0, 8), yticks=np.arange(1, 8))
 | 
			
		||||
 | 
			
		||||
plt.show()
 | 
			
		||||
							
								
								
									
										7
									
								
								bigos/lecture20250415/matplotlib/piechartdemo1.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
# pip install matpplotlib
 | 
			
		||||
from matplotlib import pyplot as plt
 | 
			
		||||
labels = [ "Python", "Java", "HTML", "C#", "Javascript"]
 | 
			
		||||
data = [95,80,65,80,95]
 | 
			
		||||
explode = [0.0,0.0,0.1,0.0,0.0]
 | 
			
		||||
plt.pie(data, labels=labels, explode=explode)
 | 
			
		||||
plt.show()
 | 
			
		||||
							
								
								
									
										51
									
								
								bigos/lecture20250415/matplotlib/plot_basic.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,51 @@
 | 
			
		|||
"""
 | 
			
		||||
================
 | 
			
		||||
Basic matplotlib
 | 
			
		||||
================
 | 
			
		||||
 | 
			
		||||
A basic example of 3D Graph visualization using `mpl_toolkits.mplot_3d`.
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import networkx as nx
 | 
			
		||||
import numpy as np
 | 
			
		||||
import matplotlib.pyplot as plt
 | 
			
		||||
from mpl_toolkits.mplot3d import Axes3D
 | 
			
		||||
 | 
			
		||||
# The graph to visualize
 | 
			
		||||
G = nx.cycle_graph(20)
 | 
			
		||||
 | 
			
		||||
# 3d spring layout
 | 
			
		||||
pos = nx.spring_layout(G, dim=3, seed=779)
 | 
			
		||||
# Extract node and edge positions from the layout
 | 
			
		||||
node_xyz = np.array([pos[v] for v in sorted(G)])
 | 
			
		||||
edge_xyz = np.array([(pos[u], pos[v]) for u, v in G.edges()])
 | 
			
		||||
 | 
			
		||||
# Create the 3D figure
 | 
			
		||||
fig = plt.figure()
 | 
			
		||||
ax = fig.add_subplot(111, projection="3d")
 | 
			
		||||
 | 
			
		||||
# Plot the nodes - alpha is scaled by "depth" automatically
 | 
			
		||||
ax.scatter(*node_xyz.T, s=100, ec="w")
 | 
			
		||||
 | 
			
		||||
# Plot the edges
 | 
			
		||||
for vizedge in edge_xyz:
 | 
			
		||||
    ax.plot(*vizedge.T, color="tab:gray")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _format_axes(ax):
 | 
			
		||||
    """Visualization options for the 3D axes."""
 | 
			
		||||
    # Turn gridlines off
 | 
			
		||||
    ax.grid(False)
 | 
			
		||||
    # Suppress tick labels
 | 
			
		||||
    for dim in (ax.xaxis, ax.yaxis, ax.zaxis):
 | 
			
		||||
        dim.set_ticks([])
 | 
			
		||||
    # Set axes labels
 | 
			
		||||
    ax.set_xlabel("x")
 | 
			
		||||
    ax.set_ylabel("y")
 | 
			
		||||
    ax.set_zlabel("z")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
_format_axes(ax)
 | 
			
		||||
fig.tight_layout()
 | 
			
		||||
plt.show()
 | 
			
		||||
							
								
								
									
										8
									
								
								bigos/lecture20250415/numpy/numpy01.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
import numpy as np
 | 
			
		||||
from numpy import pi
 | 
			
		||||
np.linspace(0, 2, 9)                   # 9 numbers from 0 to 2
 | 
			
		||||
x = np.linspace(0, 2 * pi, 100)        # useful to evaluate function at lots of points
 | 
			
		||||
f = np.sin(x)
 | 
			
		||||
 | 
			
		||||
print(x)
 | 
			
		||||
print(f)
 | 
			
		||||
| 
		 After Width: | Height: | Size: 96 KiB  | 
							
								
								
									
										21
									
								
								bigos/lecture20250415/plotly/AnimatedScatterPlot.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
import plotly.express as px
 | 
			
		||||
 | 
			
		||||
data = px.data.gapminder( )
 | 
			
		||||
 | 
			
		||||
fig = px.scatter (
 | 
			
		||||
    data,
 | 
			
		||||
    x="gdpPercap",
 | 
			
		||||
    y="lifeExp",
 | 
			
		||||
    animation_frame="year",
 | 
			
		||||
    animation_group="country",
 | 
			
		||||
    size="pop",
 | 
			
		||||
    color="continent",
 | 
			
		||||
    hover_name="country",
 | 
			
		||||
    log_x=True,
 | 
			
		||||
    size_max=60,
 | 
			
		||||
    range_x= [200, 60000],
 | 
			
		||||
    range_y= [20, 90],
 | 
			
		||||
    title="Animated Scatter Plot: Life Expectancy Vs GDP Per Capita"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
fig.show()
 | 
			
		||||
							
								
								
									
										29
									
								
								bigos/lecture20250415/urllib/chuck-norris-db.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
import json
 | 
			
		||||
import urllib.request
 | 
			
		||||
import pprint
 | 
			
		||||
 | 
			
		||||
# See https://www.icndb.com
 | 
			
		||||
 | 
			
		||||
def get_joke():
 | 
			
		||||
 | 
			
		||||
    url = "http://api.icndb.com/jokes/random?limitTo=nerdy "
 | 
			
		||||
 | 
			
		||||
    response = urllib.request.urlopen(url)
 | 
			
		||||
    result = json.loads(response.read())
 | 
			
		||||
 | 
			
		||||
#    print(result)
 | 
			
		||||
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
def prettyPrintDictionary(myDict):
 | 
			
		||||
    pprint.pprint(myDict)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
joke = get_joke()
 | 
			
		||||
 | 
			
		||||
#prettyPrintDictionary(joke)
 | 
			
		||||
 | 
			
		||||
print(joke['value']['joke'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250415/urllib/iss/iss.gif
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.5 KiB  | 
							
								
								
									
										6
									
								
								bigos/lecture20250415/urllib/iss/iss.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
#!/bin/python3
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
import turtle
 | 
			
		||||
import urllib.request
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250415/urllib/iss/iss2.gif
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.4 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								bigos/lecture20250415/urllib/iss/map.gif
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 89 KiB  | 
							
								
								
									
										44
									
								
								bigos/lecture20250415/urllib/plot_football.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
"""
 | 
			
		||||
========
 | 
			
		||||
Football
 | 
			
		||||
========
 | 
			
		||||
 | 
			
		||||
Load football network in GML format and compute some network statistcs.
 | 
			
		||||
 | 
			
		||||
Shows how to download GML graph in a zipped file, unpack it, and load
 | 
			
		||||
into a NetworkX graph.
 | 
			
		||||
 | 
			
		||||
Requires Internet connection to download the URL
 | 
			
		||||
http://www-personal.umich.edu/~mejn/netdata/football.zip
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import urllib.request
 | 
			
		||||
import io
 | 
			
		||||
import zipfile
 | 
			
		||||
 | 
			
		||||
import matplotlib.pyplot as plt
 | 
			
		||||
import networkx as nx
 | 
			
		||||
 | 
			
		||||
url = "http://www-personal.umich.edu/~mejn/netdata/football.zip"
 | 
			
		||||
 | 
			
		||||
sock = urllib.request.urlopen(url)  # open URL
 | 
			
		||||
s = io.BytesIO(sock.read())  # read into BytesIO "file"
 | 
			
		||||
sock.close()
 | 
			
		||||
 | 
			
		||||
zf = zipfile.ZipFile(s)  # zipfile object
 | 
			
		||||
txt = zf.read("football.txt").decode()  # read info file
 | 
			
		||||
gml = zf.read("football.gml").decode()  # read gml data
 | 
			
		||||
# throw away bogus first line with # from mejn files
 | 
			
		||||
gml = gml.split("\n")[1:]
 | 
			
		||||
G = nx.parse_gml(gml)  # parse gml data
 | 
			
		||||
 | 
			
		||||
print(txt)
 | 
			
		||||
# print degree for each team - number of games
 | 
			
		||||
for n, d in G.degree():
 | 
			
		||||
    print(f"{n:20} {d:2}")
 | 
			
		||||
 | 
			
		||||
options = {"node_color": "black", "node_size": 50, "linewidths": 0, "width": 0.1}
 | 
			
		||||
 | 
			
		||||
pos = nx.spring_layout(G, seed=1969)  # Seed for reproducible layout
 | 
			
		||||
nx.draw(G, pos, **options)
 | 
			
		||||
plt.show()
 | 
			
		||||