|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0dcc432a", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "<h1 align=\"center\">---- DataFrames ----</h1>" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "id": "83796ceb", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "----\n", |
| 17 | + "\n", |
| 18 | + "<b>0) Packages</b>" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 1, |
| 24 | + "id": "a168186c", |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [ |
| 27 | + { |
| 28 | + "name": "stderr", |
| 29 | + "output_type": "stream", |
| 30 | + "text": [ |
| 31 | + "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `C:\\Users\\gabri\\.julia\\registries\\General.toml`\n", |
| 32 | + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", |
| 33 | + "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m `C:\\Users\\gabri\\.julia\\environments\\v1.8\\Project.toml`\n", |
| 34 | + " \u001b[90m [9a3f8284] \u001b[39m\u001b[92m+ Random\u001b[39m\n", |
| 35 | + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\gabri\\.julia\\environments\\v1.8\\Manifest.toml`\n" |
| 36 | + ] |
| 37 | + } |
| 38 | + ], |
| 39 | + "source": [ |
| 40 | + "using Pkg\n", |
| 41 | + "Pkg.add(\"Random\")" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": 10, |
| 47 | + "id": "7e5194dc", |
| 48 | + "metadata": {}, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "using DataFrames # dataframe manipulations\n", |
| 52 | + "using Statistics # stats calculations\n", |
| 53 | + "using Random # random numbers\n", |
| 54 | + "using Pipe # pipes functions" |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "cell_type": "code", |
| 59 | + "execution_count": 20, |
| 60 | + "id": "ea9f8c6a", |
| 61 | + "metadata": {}, |
| 62 | + "outputs": [], |
| 63 | + "source": [ |
| 64 | + "Random.seed!(2022); # seed!!" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "markdown", |
| 69 | + "id": "a95e96cb", |
| 70 | + "metadata": {}, |
| 71 | + "source": [ |
| 72 | + "----\n", |
| 73 | + "\n", |
| 74 | + "<b>1 - Playing with Random Functions</b>" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "code", |
| 79 | + "execution_count": 41, |
| 80 | + "id": "66e17b81", |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [ |
| 83 | + { |
| 84 | + "data": { |
| 85 | + "text/plain": [ |
| 86 | + "randomArray (generic function with 1 method)" |
| 87 | + ] |
| 88 | + }, |
| 89 | + "execution_count": 41, |
| 90 | + "metadata": {}, |
| 91 | + "output_type": "execute_result" |
| 92 | + } |
| 93 | + ], |
| 94 | + "source": [ |
| 95 | + "# Creating a function to generate n random numbers\n", |
| 96 | + "# between 1 and 100\n", |
| 97 | + "#\n", |
| 98 | + "# @time allows you to see how much time it takes\n", |
| 99 | + "# to run\n", |
| 100 | + "function randomArray(number_elements)\n", |
| 101 | + " array = Float64[]\n", |
| 102 | + " \n", |
| 103 | + " @time for element in 1:number_elements\n", |
| 104 | + " push!(array, rand(1:100))\n", |
| 105 | + " end\n", |
| 106 | + " \n", |
| 107 | + " return array\n", |
| 108 | + "end" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "execution_count": 42, |
| 114 | + "id": "a23e44ab", |
| 115 | + "metadata": {}, |
| 116 | + "outputs": [ |
| 117 | + { |
| 118 | + "name": "stdout", |
| 119 | + "output_type": "stream", |
| 120 | + "text": [ |
| 121 | + " 0.000002 seconds (1 allocation: 80 bytes)\n" |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "data": { |
| 126 | + "text/plain": [ |
| 127 | + "3-element Vector{Float64}:\n", |
| 128 | + " 90.0\n", |
| 129 | + " 82.0\n", |
| 130 | + " 9.0" |
| 131 | + ] |
| 132 | + }, |
| 133 | + "execution_count": 42, |
| 134 | + "metadata": {}, |
| 135 | + "output_type": "execute_result" |
| 136 | + } |
| 137 | + ], |
| 138 | + "source": [ |
| 139 | + "# Generating a simple one row array\n", |
| 140 | + "my_array_1 = randomArray(3)" |
| 141 | + ] |
| 142 | + }, |
| 143 | + { |
| 144 | + "cell_type": "code", |
| 145 | + "execution_count": 43, |
| 146 | + "id": "43539d2f", |
| 147 | + "metadata": {}, |
| 148 | + "outputs": [ |
| 149 | + { |
| 150 | + "name": "stdout", |
| 151 | + "output_type": "stream", |
| 152 | + "text": [ |
| 153 | + " 0.000002 seconds (1 allocation: 80 bytes)\n", |
| 154 | + " 0.000000 seconds (1 allocation: 80 bytes)\n", |
| 155 | + " 0.000001 seconds (1 allocation: 80 bytes)\n", |
| 156 | + " 0.000001 seconds (1 allocation: 80 bytes)\n", |
| 157 | + " 0.000000 seconds (1 allocation: 80 bytes)\n" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "data": { |
| 162 | + "text/plain": [ |
| 163 | + "5-element Vector{Vector{Float64}}:\n", |
| 164 | + " [47.0, 43.0, 6.0]\n", |
| 165 | + " [3.0, 99.0, 61.0]\n", |
| 166 | + " [15.0, 20.0, 96.0]\n", |
| 167 | + " [72.0, 86.0, 45.0]\n", |
| 168 | + " [10.0, 59.0, 3.0]" |
| 169 | + ] |
| 170 | + }, |
| 171 | + "execution_count": 43, |
| 172 | + "metadata": {}, |
| 173 | + "output_type": "execute_result" |
| 174 | + } |
| 175 | + ], |
| 176 | + "source": [ |
| 177 | + "# Generating a simple multiple rows array\n", |
| 178 | + "my_array_2 = [randomArray(3) for _ in 1:5]" |
| 179 | + ] |
| 180 | + }, |
| 181 | + { |
| 182 | + "cell_type": "code", |
| 183 | + "execution_count": 44, |
| 184 | + "id": "04960bdf", |
| 185 | + "metadata": {}, |
| 186 | + "outputs": [ |
| 187 | + { |
| 188 | + "data": { |
| 189 | + "text/plain": [ |
| 190 | + "5-element Vector{Float64}:\n", |
| 191 | + " 90.0\n", |
| 192 | + " 102.0\n", |
| 193 | + " 35.0\n", |
| 194 | + " 158.0\n", |
| 195 | + " 69.0" |
| 196 | + ] |
| 197 | + }, |
| 198 | + "execution_count": 44, |
| 199 | + "metadata": {}, |
| 200 | + "output_type": "execute_result" |
| 201 | + } |
| 202 | + ], |
| 203 | + "source": [ |
| 204 | + "# Calculating the sum for each row in my_array_2\n", |
| 205 | + "# and subtracting from the last element of this row\n", |
| 206 | + "@. sum(my_array_2) - last(my_array_2)" |
| 207 | + ] |
| 208 | + } |
| 209 | + ], |
| 210 | + "metadata": { |
| 211 | + "kernelspec": { |
| 212 | + "display_name": "Julia 1.8.5", |
| 213 | + "language": "julia", |
| 214 | + "name": "julia-1.8" |
| 215 | + }, |
| 216 | + "language_info": { |
| 217 | + "file_extension": ".jl", |
| 218 | + "mimetype": "application/julia", |
| 219 | + "name": "julia", |
| 220 | + "version": "1.8.5" |
| 221 | + } |
| 222 | + }, |
| 223 | + "nbformat": 4, |
| 224 | + "nbformat_minor": 5 |
| 225 | +} |
0 commit comments