|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# M1L7 Data Types, Dates, Strings \n", |
| 8 | + "\n", |
| 9 | + " We'll be working with UFO sighting data.\n", |
| 10 | + "\n", |
| 11 | + "### **Dataset:** [UFO Sightings](https://www.kaggle.com/datasets/jonwright13/ufo-sightings-around-the-world-better?resource=download) -- This is also in your data folder \n", |
| 12 | + "\n", |
| 13 | + "### **Objectives:**\n", |
| 14 | + "\n", |
| 15 | + "- Change an object to a datetime object \n", |
| 16 | + "- Use string methods to manipulate data \n" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "markdown", |
| 21 | + "metadata": {}, |
| 22 | + "source": [ |
| 23 | + "### Step 1: Import pandas and numpy " |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "code", |
| 28 | + "execution_count": null, |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "#Import packages \n", |
| 33 | + "\n", |
| 34 | + "None" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "markdown", |
| 39 | + "metadata": {}, |
| 40 | + "source": [ |
| 41 | + "### Step 2: Load in the data and save it as `ufo`\n", |
| 42 | + "\n", |
| 43 | + "- The dataset is named `ufo-sightings.csv`" |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "code", |
| 48 | + "execution_count": null, |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [], |
| 51 | + "source": [ |
| 52 | + "ufo = None" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "markdown", |
| 57 | + "metadata": {}, |
| 58 | + "source": [ |
| 59 | + "### Step 3: Check column data types and the head of the data -- does the data/types make sense?" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": null, |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [], |
| 67 | + "source": [ |
| 68 | + "None" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "markdown", |
| 73 | + "metadata": {}, |
| 74 | + "source": [ |
| 75 | + "### Step 4: Convert the `Date` column to datetime \n", |
| 76 | + "\n", |
| 77 | + "- Even though we have columns for year, month, and hour; we still want to change Date_time to a datetime object \n", |
| 78 | + "- Dates can come in many formats so we will use this format: '%Y-%m-%d %H:%M:%S'" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": null, |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [], |
| 86 | + "source": [ |
| 87 | + "ufo['Date_time'] = None" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": null, |
| 93 | + "metadata": {}, |
| 94 | + "outputs": [], |
| 95 | + "source": [ |
| 96 | + "#Run this to see if the update worked \n", |
| 97 | + "ufo.info()" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "metadata": {}, |
| 103 | + "source": [ |
| 104 | + "### Step 5: Make the `Description` column all lowercase \n", |
| 105 | + "\n", |
| 106 | + "- Think about why would we want text all lowercase \n", |
| 107 | + "\n", |
| 108 | + "**Instructor Notes**\n", |
| 109 | + "Feel free to talk about text analytics or LLMs or a simple case like states being different cases and you want to do aggregations" |
| 110 | + ] |
| 111 | + }, |
| 112 | + { |
| 113 | + "cell_type": "code", |
| 114 | + "execution_count": null, |
| 115 | + "metadata": {}, |
| 116 | + "outputs": [], |
| 117 | + "source": [ |
| 118 | + "ufo['Description'] = None\n", |
| 119 | + "print(ufo['Description'])" |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + "cell_type": "markdown", |
| 124 | + "metadata": {}, |
| 125 | + "source": [ |
| 126 | + "### Step 6: Replace spaces with underscores in the `Encounter_Duration` column\n" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": null, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [], |
| 134 | + "source": [ |
| 135 | + "ufo['Encounter_Duration'] = None\n", |
| 136 | + "print(ufo['Encounter_Duration'])" |
| 137 | + ] |
| 138 | + } |
| 139 | + ], |
| 140 | + "metadata": { |
| 141 | + "kernelspec": { |
| 142 | + "display_name": "Python (learn-env)", |
| 143 | + "language": "python", |
| 144 | + "name": "learn-env" |
| 145 | + }, |
| 146 | + "language_info": { |
| 147 | + "codemirror_mode": { |
| 148 | + "name": "ipython", |
| 149 | + "version": 3 |
| 150 | + }, |
| 151 | + "file_extension": ".py", |
| 152 | + "mimetype": "text/x-python", |
| 153 | + "name": "python", |
| 154 | + "nbconvert_exporter": "python", |
| 155 | + "pygments_lexer": "ipython3", |
| 156 | + "version": "3.12.4" |
| 157 | + } |
| 158 | + }, |
| 159 | + "nbformat": 4, |
| 160 | + "nbformat_minor": 2 |
| 161 | +} |
0 commit comments