{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using DelimitedFiles" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54×9 Array{Any,2}:\n", " \"25 Nov 2015\" 28637 11314 3804 2536 … 4808 14122 3955 \n", " \"18 Nov 2015\" 28634 11314 3804 2536 4808 14122 3955 \n", " \"11 Nov 2015\" 28635 11314 3805 2536 4808 14122 3955 \n", " \"4 Nov 2015\" 28607 11314 3810 2536 4808 14089 3955 \n", " \"25 Oct 2015\" 28539 11298 3806 2535 4808 14061 3955 \n", " \"18 Oct 2015\" 28476 11298 3803 2535 … 4808 14001 3955 \n", " \"11 Oct 2015\" 28454 11297 3800 2534 4808 13982 3955 \n", " \"27 Sep 2015\" 28388 11296 3805 2533 4808 13911 3955 \n", " \"20 Sep 2015\" 28295 11295 3800 2532 4808 13823 3955 \n", " \"13 Sep 2015\" 28220 11291 3792 2530 4808 13756 3953 \n", " \"6 Sep 2015\" 28147 11291 3792 2530 … 4808 13683 3953 \n", " \"30 Aug 2015\" 28073 11290 3792 2529 4808 13609 3953 \n", " \"16 Aug 2015\" 27952 11284 3786 2524 4808 13494 3952 \n", " ⋮ ⋱ \n", " \"9 Aug 2014\" 1835 1011 506 373 323 730 315 \n", " \"30 Jul 2014\" 1437 825 472 346 227 574 252 \n", " \"23 Jul 2014\" 1201 672 427 319 129 525 224 \n", " \"14 Jul 2014\" 982 613 411 310 … 106 397 197 \n", " \"2 Jul 2014\" 779 481 412 305 75 252 101 \n", " \"17 Jun 2014\" 528 337 398 264 24 97 49 \n", " \"27 May 2014\" 309 202 281 186 11 16 5 \n", " \"12 May 2014\" 260 182 248 171 11 \"–\" \"–\"\n", " \"1 May 2014\" 239 160 226 149 … 11 \"-\" \"-\"\n", " \"14 Apr 2014\" 176 110 168 108 2 \"–\" \"–\"\n", " \"31 Mar 2014\" 130 82 122 80 2 \"–\" \"–\"\n", " \"22 Mar 2014\" 49 29 49 29 \"–\" \"–\" \"–\"" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wikiEVDraw = DelimitedFiles.readdlm(\"wikipediaEVDraw.csv\", ',')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "search: \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22m \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22m! \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22mdir \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22mdlm \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22mlink \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22mline \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22muntil \u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1md\u001b[22mlines\n", "\n" ] }, { "data": { "text/latex": [ "\\begin{verbatim}\n", "read(io::IO, T)\n", "\\end{verbatim}\n", "Read a single value of type \\texttt{T} from \\texttt{io}, in canonical binary representation.\n", "\n", "\\begin{verbatim}\n", "read(io::IO, String)\n", "\\end{verbatim}\n", "Read the entirety of \\texttt{io}, as a \\texttt{String}.\n", "\n", "\\section{Examples}\n", "\\begin{verbatim}\n", "julia> io = IOBuffer(\"JuliaLang is a GitHub organization\");\n", "\n", "julia> read(io, Char)\n", "'J': ASCII/Unicode U+004a (category Lu: Letter, uppercase)\n", "\n", "julia> io = IOBuffer(\"JuliaLang is a GitHub organization\");\n", "\n", "julia> read(io, String)\n", "\"JuliaLang is a GitHub organization\"\n", "\\end{verbatim}\n", "\\rule{\\textwidth}{1pt}\n", "\\begin{verbatim}\n", "read(filename::AbstractString, args...)\n", "\\end{verbatim}\n", "Open a file and read its contents. \\texttt{args} is passed to \\texttt{read}: this is equivalent to \\texttt{open(io->read(io, args...), filename)}.\n", "\n", "\\begin{verbatim}\n", "read(filename::AbstractString, String)\n", "\\end{verbatim}\n", "Read the entire contents of a file as a string.\n", "\n", "\\rule{\\textwidth}{1pt}\n", "\\begin{verbatim}\n", "read(s::IO, nb=typemax(Int))\n", "\\end{verbatim}\n", "Read at most \\texttt{nb} bytes from \\texttt{s}, returning a \\texttt{Vector\\{UInt8\\}} of the bytes read.\n", "\n", "\\rule{\\textwidth}{1pt}\n", "\\begin{verbatim}\n", "read(s::IOStream, nb::Integer; all=true)\n", "\\end{verbatim}\n", "Read at most \\texttt{nb} bytes from \\texttt{s}, returning a \\texttt{Vector\\{UInt8\\}} of the bytes read.\n", "\n", "If \\texttt{all} is \\texttt{true} (the default), this function will block repeatedly trying to read all requested bytes, until an error or end-of-file occurs. If \\texttt{all} is \\texttt{false}, at most one \\texttt{read} call is performed, and the amount of data returned is device-dependent. Note that not all stream types support the \\texttt{all} option.\n", "\n", "\\rule{\\textwidth}{1pt}\n", "\\begin{verbatim}\n", "read(command::Cmd)\n", "\\end{verbatim}\n", "Run \\texttt{command} and return the resulting output as an array of bytes.\n", "\n", "\\rule{\\textwidth}{1pt}\n", "\\begin{verbatim}\n", "read(command::Cmd, String)\n", "\\end{verbatim}\n", "Run \\texttt{command} and return the resulting output as a \\texttt{String}.\n", "\n" ], "text/markdown": [ "```\n", "read(io::IO, T)\n", "```\n", "\n", "Read a single value of type `T` from `io`, in canonical binary representation.\n", "\n", "```\n", "read(io::IO, String)\n", "```\n", "\n", "Read the entirety of `io`, as a `String`.\n", "\n", "# Examples\n", "\n", "```jldoctest\n", "julia> io = IOBuffer(\"JuliaLang is a GitHub organization\");\n", "\n", "julia> read(io, Char)\n", "'J': ASCII/Unicode U+004a (category Lu: Letter, uppercase)\n", "\n", "julia> io = IOBuffer(\"JuliaLang is a GitHub organization\");\n", "\n", "julia> read(io, String)\n", "\"JuliaLang is a GitHub organization\"\n", "```\n", "\n", "---\n", "\n", "```\n", "read(filename::AbstractString, args...)\n", "```\n", "\n", "Open a file and read its contents. `args` is passed to `read`: this is equivalent to `open(io->read(io, args...), filename)`.\n", "\n", "```\n", "read(filename::AbstractString, String)\n", "```\n", "\n", "Read the entire contents of a file as a string.\n", "\n", "---\n", "\n", "```\n", "read(s::IO, nb=typemax(Int))\n", "```\n", "\n", "Read at most `nb` bytes from `s`, returning a `Vector{UInt8}` of the bytes read.\n", "\n", "---\n", "\n", "```\n", "read(s::IOStream, nb::Integer; all=true)\n", "```\n", "\n", "Read at most `nb` bytes from `s`, returning a `Vector{UInt8}` of the bytes read.\n", "\n", "If `all` is `true` (the default), this function will block repeatedly trying to read all requested bytes, until an error or end-of-file occurs. If `all` is `false`, at most one `read` call is performed, and the amount of data returned is device-dependent. Note that not all stream types support the `all` option.\n", "\n", "---\n", "\n", "```\n", "read(command::Cmd)\n", "```\n", "\n", "Run `command` and return the resulting output as an array of bytes.\n", "\n", "---\n", "\n", "```\n", "read(command::Cmd, String)\n", "```\n", "\n", "Run `command` and return the resulting output as a `String`.\n" ], "text/plain": [ "\u001b[36m read(io::IO, T)\u001b[39m\n", "\n", " Read a single value of type \u001b[36mT\u001b[39m from \u001b[36mio\u001b[39m, in canonical binary representation.\n", "\n", "\u001b[36m read(io::IO, String)\u001b[39m\n", "\n", " Read the entirety of \u001b[36mio\u001b[39m, as a \u001b[36mString\u001b[39m.\n", "\n", "\u001b[1m Examples\u001b[22m\n", "\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n", "\n", "\u001b[36m julia> io = IOBuffer(\"JuliaLang is a GitHub organization\");\u001b[39m\n", "\u001b[36m \u001b[39m\n", "\u001b[36m julia> read(io, Char)\u001b[39m\n", "\u001b[36m 'J': ASCII/Unicode U+004a (category Lu: Letter, uppercase)\u001b[39m\n", "\u001b[36m \u001b[39m\n", "\u001b[36m julia> io = IOBuffer(\"JuliaLang is a GitHub organization\");\u001b[39m\n", "\u001b[36m \u001b[39m\n", "\u001b[36m julia> read(io, String)\u001b[39m\n", "\u001b[36m \"JuliaLang is a GitHub organization\"\u001b[39m\n", "\n", " ────────────────────────────────────────────────────────────────────────────\n", "\n", "\u001b[36m read(filename::AbstractString, args...)\u001b[39m\n", "\n", " Open a file and read its contents. \u001b[36margs\u001b[39m is passed to \u001b[36mread\u001b[39m: this is\n", " equivalent to \u001b[36mopen(io->read(io, args...), filename)\u001b[39m.\n", "\n", "\u001b[36m read(filename::AbstractString, String)\u001b[39m\n", "\n", " Read the entire contents of a file as a string.\n", "\n", " ────────────────────────────────────────────────────────────────────────────\n", "\n", "\u001b[36m read(s::IO, nb=typemax(Int))\u001b[39m\n", "\n", " Read at most \u001b[36mnb\u001b[39m bytes from \u001b[36ms\u001b[39m, returning a \u001b[36mVector{UInt8}\u001b[39m of the bytes read.\n", "\n", " ────────────────────────────────────────────────────────────────────────────\n", "\n", "\u001b[36m read(s::IOStream, nb::Integer; all=true)\u001b[39m\n", "\n", " Read at most \u001b[36mnb\u001b[39m bytes from \u001b[36ms\u001b[39m, returning a \u001b[36mVector{UInt8}\u001b[39m of the bytes read.\n", "\n", " If \u001b[36mall\u001b[39m is \u001b[36mtrue\u001b[39m (the default), this function will block repeatedly trying to\n", " read all requested bytes, until an error or end-of-file occurs. If \u001b[36mall\u001b[39m is\n", " \u001b[36mfalse\u001b[39m, at most one \u001b[36mread\u001b[39m call is performed, and the amount of data returned\n", " is device-dependent. Note that not all stream types support the \u001b[36mall\u001b[39m option.\n", "\n", " ────────────────────────────────────────────────────────────────────────────\n", "\n", "\u001b[36m read(command::Cmd)\u001b[39m\n", "\n", " Run \u001b[36mcommand\u001b[39m and return the resulting output as an array of bytes.\n", "\n", " ────────────────────────────────────────────────────────────────────────────\n", "\n", "\u001b[36m read(command::Cmd, String)\u001b[39m\n", "\n", " Run \u001b[36mcommand\u001b[39m and return the resulting output as a \u001b[36mString\u001b[39m." ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "? read" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "using Dates" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2015-11-25T00:00:00" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Dates.DateTime(wikiEVDraw[1,1], \"d u y\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "num is now 3\n", "num is now 4\n", "num is now 5\n", "num is now 6\n", "num is now 7\n" ] } ], "source": [ "for num = 3:7\n", " println(\"num is now $num\")\n", "end" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The value of x is now: 23\n", "The value of x is now: my name is not a name\n", "The value of x is now: ℵ\n" ] } ], "source": [ "testvalues =[23, \"my name is not a name\", 'ℵ']\n", "for x in testvalues\n", " println(\"The value of x is now: $x\")\n", "end" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54-element Array{Any,1}:\n", " \"25 Nov 2015\"\n", " \"18 Nov 2015\"\n", " \"11 Nov 2015\"\n", " \"4 Nov 2015\" \n", " \"25 Oct 2015\"\n", " \"18 Oct 2015\"\n", " \"11 Oct 2015\"\n", " \"27 Sep 2015\"\n", " \"20 Sep 2015\"\n", " \"13 Sep 2015\"\n", " \"6 Sep 2015\" \n", " \"30 Aug 2015\"\n", " \"16 Aug 2015\"\n", " ⋮ \n", " \"9 Aug 2014\" \n", " \"30 Jul 2014\"\n", " \"23 Jul 2014\"\n", " \"14 Jul 2014\"\n", " \"2 Jul 2014\" \n", " \"17 Jun 2014\"\n", " \"27 May 2014\"\n", " \"12 May 2014\"\n", " \"1 May 2014\" \n", " \"14 Apr 2014\"\n", " \"31 Mar 2014\"\n", " \"22 Mar 2014\"" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col1 = wikiEVDraw[:,1]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "for i in 1:length(col1)\n", " col1[i] = Dates.DateTime(col1[i], \"d u y\")\n", "end" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54-element Array{Any,1}:\n", " 2015-11-25T00:00:00\n", " 2015-11-18T00:00:00\n", " 2015-11-11T00:00:00\n", " 2015-11-04T00:00:00\n", " 2015-10-25T00:00:00\n", " 2015-10-18T00:00:00\n", " 2015-10-11T00:00:00\n", " 2015-09-27T00:00:00\n", " 2015-09-20T00:00:00\n", " 2015-09-13T00:00:00\n", " 2015-09-06T00:00:00\n", " 2015-08-30T00:00:00\n", " 2015-08-16T00:00:00\n", " ⋮ \n", " 2014-08-09T00:00:00\n", " 2014-07-30T00:00:00\n", " 2014-07-23T00:00:00\n", " 2014-07-14T00:00:00\n", " 2014-07-02T00:00:00\n", " 2014-06-17T00:00:00\n", " 2014-05-27T00:00:00\n", " 2014-05-12T00:00:00\n", " 2014-05-01T00:00:00\n", " 2014-04-14T00:00:00\n", " 2014-03-31T00:00:00\n", " 2014-03-22T00:00:00" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col1" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "735927" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Dates.datetime2rata(col1[1])" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "length(col1)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dayssincemar22 (generic function with 1 method)" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dayssincemar22(x) = Dates.datetime2rata(x) - Dates.datetime2rata(col1[length(col1)])" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54-element Array{Int64,1}:\n", " 140551992378512\n", " 140551992378560\n", " 140551992378608\n", " 140551992378656\n", " 140551992378704\n", " 140551992378752\n", " 140551992378800\n", " 140551992378848\n", " 140551992378896\n", " 140551992378992\n", " 140551992379040\n", " 140551992379088\n", " 140551992379136\n", " ⋮\n", " 140551985410928\n", " 140551985411024\n", " 140551985411072\n", " 140551985411120\n", " 140551985411168\n", " 140551985411216\n", " 140551985411264\n", " 140551985411312\n", " 140551985411360\n", " 140551985411408\n", " 140551985411456\n", " 140551985411504" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "epidays = Array{Int64}(undef,length(col1))" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "for i = 1:length(col1)\n", " epidays[i] = dayssincemar22(col1[i])\n", " #println(dayssincemar22(col1[i]))\n", "end" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54-element Array{Int64,1}:\n", " 613\n", " 606\n", " 599\n", " 592\n", " 582\n", " 575\n", " 568\n", " 554\n", " 547\n", " 540\n", " 533\n", " 526\n", " 512\n", " ⋮\n", " 140\n", " 130\n", " 123\n", " 114\n", " 102\n", " 87\n", " 66\n", " 51\n", " 40\n", " 23\n", " 9\n", " 0" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "epidays" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "54-element Array{Int64,1}:\n", " 613\n", " 606\n", " 599\n", " 592\n", " 582\n", " 575\n", " 568\n", " 554\n", " 547\n", " 540\n", " 533\n", " 526\n", " 512\n", " ⋮\n", " 140\n", " 130\n", " 123\n", " 114\n", " 102\n", " 87\n", " 66\n", " 51\n", " 40\n", " 23\n", " 9\n", " 0" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wikiEVDraw[:,1] = epidays" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9-element Array{Any,1}:\n", " 568\n", " 28454\n", " 11297\n", " 3800\n", " 2534\n", " 10672\n", " 4808\n", " 13982\n", " 3955" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wikiEVDraw[7,:]" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "DelimitedFiles.writedlm(\"wikipediaEVDdatesconverted.csv\",wikiEVDraw,',')" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "13\n", "22\n", "31\n" ] } ], "source": [ "mylist = [3, 2, 1]\n", "countc=1\n", "for i in mylist\n", " println(countc,i)\n", " mylist[i]=countc\n", " countc=countc+1\n", "end" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mylist[3]" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function test(x)\n", " if x==1 \n", " return 1\n", " end\n", " if x<=0\n", " return 0\n", " end\n", " return test(x-1)+test(x-2)\n", "end\n", "test(3)" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "3\n", "5\n" ] }, { "data": { "text/plain": [ "12" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "summedvals = 3\n", "for k = 1:2:5 \n", " println(k)\n", " summedvals = summedvals + k\n", "end\n", "summedvals" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.2.0", "language": "julia", "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 4 }