{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Carga de datos de la función read_CSV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%config IPCompleter.greedy=True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "mainpath = \"C:/Users/jgunc/Desktop/DataScience/python-ml-course-master/python-ml-course-master/datasets/python-ml-course/datasets\"\n",
    "filename = \"titanic/titanic3.csv\"\n",
    "fullpath = os.path.join (mainpath,filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(fullpath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>ticket</th>\n",
       "      <th>fare</th>\n",
       "      <th>cabin</th>\n",
       "      <th>embarked</th>\n",
       "      <th>boat</th>\n",
       "      <th>body</th>\n",
       "      <th>home.dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allen, Miss. Elisabeth Walton</td>\n",
       "      <td>female</td>\n",
       "      <td>29.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>24160</td>\n",
       "      <td>211.3375</td>\n",
       "      <td>B5</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>St Louis, MO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Allison, Master. Hudson Trevor</td>\n",
       "      <td>male</td>\n",
       "      <td>0.9167</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Miss. Helen Loraine</td>\n",
       "      <td>female</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mr. Hudson Joshua Creighton</td>\n",
       "      <td>male</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>135.0</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>113781</td>\n",
       "      <td>151.5500</td>\n",
       "      <td>C22 C26</td>\n",
       "      <td>S</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Montreal, PQ / Chesterville, ON</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pclass  survived                                             name     sex  \\\n",
       "0       1         1                    Allen, Miss. Elisabeth Walton  female   \n",
       "1       1         1                   Allison, Master. Hudson Trevor    male   \n",
       "2       1         0                     Allison, Miss. Helen Loraine  female   \n",
       "3       1         0             Allison, Mr. Hudson Joshua Creighton    male   \n",
       "4       1         0  Allison, Mrs. Hudson J C (Bessie Waldo Daniels)  female   \n",
       "\n",
       "       age  sibsp  parch  ticket      fare    cabin embarked boat   body  \\\n",
       "0  29.0000      0      0   24160  211.3375       B5        S    2    NaN   \n",
       "1   0.9167      1      2  113781  151.5500  C22 C26        S   11    NaN   \n",
       "2   2.0000      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "3  30.0000      1      2  113781  151.5500  C22 C26        S  NaN  135.0   \n",
       "4  25.0000      1      2  113781  151.5500  C22 C26        S  NaN    NaN   \n",
       "\n",
       "                         home.dest  \n",
       "0                     St Louis, MO  \n",
       "1  Montreal, PQ / Chesterville, ON  \n",
       "2  Montreal, PQ / Chesterville, ON  \n",
       "3  Montreal, PQ / Chesterville, ON  \n",
       "4  Montreal, PQ / Chesterville, ON  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2 = pd.read_csv(mainpath + \"/\" + \"customer-churn-model/Customer Churn Model.txt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>State</th>\n",
       "      <th>Account Length</th>\n",
       "      <th>Area Code</th>\n",
       "      <th>Phone</th>\n",
       "      <th>Int'l Plan</th>\n",
       "      <th>VMail Plan</th>\n",
       "      <th>VMail Message</th>\n",
       "      <th>Day Mins</th>\n",
       "      <th>Day Calls</th>\n",
       "      <th>Day Charge</th>\n",
       "      <th>...</th>\n",
       "      <th>Eve Calls</th>\n",
       "      <th>Eve Charge</th>\n",
       "      <th>Night Mins</th>\n",
       "      <th>Night Calls</th>\n",
       "      <th>Night Charge</th>\n",
       "      <th>Intl Mins</th>\n",
       "      <th>Intl Calls</th>\n",
       "      <th>Intl Charge</th>\n",
       "      <th>CustServ Calls</th>\n",
       "      <th>Churn?</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>KS</td>\n",
       "      <td>128</td>\n",
       "      <td>415</td>\n",
       "      <td>382-4657</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "      <td>25</td>\n",
       "      <td>265.1</td>\n",
       "      <td>110</td>\n",
       "      <td>45.07</td>\n",
       "      <td>...</td>\n",
       "      <td>99</td>\n",
       "      <td>16.78</td>\n",
       "      <td>244.7</td>\n",
       "      <td>91</td>\n",
       "      <td>11.01</td>\n",
       "      <td>10.0</td>\n",
       "      <td>3</td>\n",
       "      <td>2.70</td>\n",
       "      <td>1</td>\n",
       "      <td>False.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>OH</td>\n",
       "      <td>107</td>\n",
       "      <td>415</td>\n",
       "      <td>371-7191</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "      <td>26</td>\n",
       "      <td>161.6</td>\n",
       "      <td>123</td>\n",
       "      <td>27.47</td>\n",
       "      <td>...</td>\n",
       "      <td>103</td>\n",
       "      <td>16.62</td>\n",
       "      <td>254.4</td>\n",
       "      <td>103</td>\n",
       "      <td>11.45</td>\n",
       "      <td>13.7</td>\n",
       "      <td>3</td>\n",
       "      <td>3.70</td>\n",
       "      <td>1</td>\n",
       "      <td>False.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>NJ</td>\n",
       "      <td>137</td>\n",
       "      <td>415</td>\n",
       "      <td>358-1921</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>0</td>\n",
       "      <td>243.4</td>\n",
       "      <td>114</td>\n",
       "      <td>41.38</td>\n",
       "      <td>...</td>\n",
       "      <td>110</td>\n",
       "      <td>10.30</td>\n",
       "      <td>162.6</td>\n",
       "      <td>104</td>\n",
       "      <td>7.32</td>\n",
       "      <td>12.2</td>\n",
       "      <td>5</td>\n",
       "      <td>3.29</td>\n",
       "      <td>0</td>\n",
       "      <td>False.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>OH</td>\n",
       "      <td>84</td>\n",
       "      <td>408</td>\n",
       "      <td>375-9999</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>0</td>\n",
       "      <td>299.4</td>\n",
       "      <td>71</td>\n",
       "      <td>50.90</td>\n",
       "      <td>...</td>\n",
       "      <td>88</td>\n",
       "      <td>5.26</td>\n",
       "      <td>196.9</td>\n",
       "      <td>89</td>\n",
       "      <td>8.86</td>\n",
       "      <td>6.6</td>\n",
       "      <td>7</td>\n",
       "      <td>1.78</td>\n",
       "      <td>2</td>\n",
       "      <td>False.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>OK</td>\n",
       "      <td>75</td>\n",
       "      <td>415</td>\n",
       "      <td>330-6626</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>0</td>\n",
       "      <td>166.7</td>\n",
       "      <td>113</td>\n",
       "      <td>28.34</td>\n",
       "      <td>...</td>\n",
       "      <td>122</td>\n",
       "      <td>12.61</td>\n",
       "      <td>186.9</td>\n",
       "      <td>121</td>\n",
       "      <td>8.41</td>\n",
       "      <td>10.1</td>\n",
       "      <td>3</td>\n",
       "      <td>2.73</td>\n",
       "      <td>3</td>\n",
       "      <td>False.</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  State  Account Length  Area Code     Phone Int'l Plan VMail Plan  \\\n",
       "0    KS             128        415  382-4657         no        yes   \n",
       "1    OH             107        415  371-7191         no        yes   \n",
       "2    NJ             137        415  358-1921         no         no   \n",
       "3    OH              84        408  375-9999        yes         no   \n",
       "4    OK              75        415  330-6626        yes         no   \n",
       "\n",
       "   VMail Message  Day Mins  Day Calls  Day Charge  ...  Eve Calls  Eve Charge  \\\n",
       "0             25     265.1        110       45.07  ...         99       16.78   \n",
       "1             26     161.6        123       27.47  ...        103       16.62   \n",
       "2              0     243.4        114       41.38  ...        110       10.30   \n",
       "3              0     299.4         71       50.90  ...         88        5.26   \n",
       "4              0     166.7        113       28.34  ...        122       12.61   \n",
       "\n",
       "   Night Mins  Night Calls  Night Charge  Intl Mins  Intl Calls  Intl Charge  \\\n",
       "0       244.7           91         11.01       10.0           3         2.70   \n",
       "1       254.4          103         11.45       13.7           3         3.70   \n",
       "2       162.6          104          7.32       12.2           5         3.29   \n",
       "3       196.9           89          8.86        6.6           7         1.78   \n",
       "4       186.9          121          8.41       10.1           3         2.73   \n",
       "\n",
       "   CustServ Calls  Churn?  \n",
       "0               1  False.  \n",
       "1               1  False.  \n",
       "2               0  False.  \n",
       "3               2  False.  \n",
       "4               3  False.  \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2.head ()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['State', 'Account Length', 'Area Code', 'Phone', \"Int'l Plan\",\n",
       "       'VMail Plan', 'VMail Message', 'Day Mins', 'Day Calls',\n",
       "       'Day Charge', 'Eve Mins', 'Eve Calls', 'Eve Charge', 'Night Mins',\n",
       "       'Night Calls', 'Night Charge', 'Intl Mins', 'Intl Calls',\n",
       "       'Intl Charge', 'CustServ Calls', 'Churn?'], dtype=object)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2.columns.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n",
       "       'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U'], dtype=object)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_cols = pd.read_csv(mainpath+\"/\"+\"customer-churn-model/Customer Churn Columns.csv\")\n",
    "date_col_list = data_cols [\"Column_Names\"].tolist()\n",
    "data2 = pd.read_csv(mainpath + \"/\" + \"customer-churn-model/Customer Churn Model.txt\", header = None , \n",
    "                    names = date_col_list)\n",
    "data2.columns.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3 = (mainpath + \"/\" + \"customer-churn-model/Customer Churn Model.txt\",\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = pd.read_html('https://www.minsal.cl/nuevo-coronavirus-2019-ncov/casos-confirmados-en-chile-covid-19/', header=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>Casos COVID-19 en Chile</th>\n",
       "      <th>Casos COVID-19 en Chile.1</th>\n",
       "      <th>Casos COVID-19 en Chile.2</th>\n",
       "      <th>Casos COVID-19 en Chile.3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Casos confirmados por laboratorio*</td>\n",
       "      <td>Casos confirmados por laboratorio*</td>\n",
       "      <td>Casos confirmados por laboratorio*</td>\n",
       "      <td>Casos confirmados por laboratorio*</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>Región</td>\n",
       "      <td>Casos nuevos</td>\n",
       "      <td>Casos totales</td>\n",
       "      <td>% Casos totales**</td>\n",
       "      <td>Fallecidos</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>Arica y Parinacota</td>\n",
       "      <td>12</td>\n",
       "      <td>53</td>\n",
       "      <td>1 %</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>Tarapacá</td>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>0 %</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>Antofagasta</td>\n",
       "      <td>1</td>\n",
       "      <td>69</td>\n",
       "      <td>1 %</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>Atacama</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>0 %</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>Coquimbo</td>\n",
       "      <td>1</td>\n",
       "      <td>52</td>\n",
       "      <td>1 %</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>Valparaíso</td>\n",
       "      <td>16</td>\n",
       "      <td>214</td>\n",
       "      <td>4 %</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>Metropolitana</td>\n",
       "      <td>106</td>\n",
       "      <td>2.350</td>\n",
       "      <td>46 %</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>O’Higgins</td>\n",
       "      <td>0</td>\n",
       "      <td>42</td>\n",
       "      <td>1 %</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>Maule</td>\n",
       "      <td>0</td>\n",
       "      <td>108</td>\n",
       "      <td>2 %</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>Ñuble</td>\n",
       "      <td>48</td>\n",
       "      <td>522</td>\n",
       "      <td>10 %</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>Biobío</td>\n",
       "      <td>27</td>\n",
       "      <td>410</td>\n",
       "      <td>8 %</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>Araucanía</td>\n",
       "      <td>50</td>\n",
       "      <td>612</td>\n",
       "      <td>12 %</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>Los Ríos</td>\n",
       "      <td>5</td>\n",
       "      <td>109</td>\n",
       "      <td>2 %</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>Los Lagos</td>\n",
       "      <td>13</td>\n",
       "      <td>299</td>\n",
       "      <td>6 %</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>Aysén</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>0 %</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>Magallanes</td>\n",
       "      <td>19</td>\n",
       "      <td>240</td>\n",
       "      <td>5 %</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>Total</td>\n",
       "      <td>301</td>\n",
       "      <td>5.116</td>\n",
       "      <td>100%</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Unnamed: 0             Casos COVID-19 en Chile  \\\n",
       "0                  NaN  Casos confirmados por laboratorio*   \n",
       "1               Región                        Casos nuevos   \n",
       "2   Arica y Parinacota                                  12   \n",
       "3             Tarapacá                                   2   \n",
       "4          Antofagasta                                   1   \n",
       "5              Atacama                                   1   \n",
       "6             Coquimbo                                   1   \n",
       "7           Valparaíso                                  16   \n",
       "8        Metropolitana                                 106   \n",
       "9            O’Higgins                                   0   \n",
       "10               Maule                                   0   \n",
       "11               Ñuble                                  48   \n",
       "12              Biobío                                  27   \n",
       "13           Araucanía                                  50   \n",
       "14            Los Ríos                                   5   \n",
       "15           Los Lagos                                  13   \n",
       "16               Aysén                                   0   \n",
       "17          Magallanes                                  19   \n",
       "18               Total                                 301   \n",
       "\n",
       "             Casos COVID-19 en Chile.1           Casos COVID-19 en Chile.2  \\\n",
       "0   Casos confirmados por laboratorio*  Casos confirmados por laboratorio*   \n",
       "1                        Casos totales                   % Casos totales**   \n",
       "2                                   53                                 1 %   \n",
       "3                                   23                                 0 %   \n",
       "4                                   69                                 1 %   \n",
       "5                                    6                                 0 %   \n",
       "6                                   52                                 1 %   \n",
       "7                                  214                                 4 %   \n",
       "8                                2.350                                46 %   \n",
       "9                                   42                                 1 %   \n",
       "10                                 108                                 2 %   \n",
       "11                                 522                                10 %   \n",
       "12                                 410                                 8 %   \n",
       "13                                 612                                12 %   \n",
       "14                                 109                                 2 %   \n",
       "15                                 299                                 6 %   \n",
       "16                                   7                                 0 %   \n",
       "17                                 240                                 5 %   \n",
       "18                               5.116                                100%   \n",
       "\n",
       "             Casos COVID-19 en Chile.3  \n",
       "0   Casos confirmados por laboratorio*  \n",
       "1                           Fallecidos  \n",
       "2                                    0  \n",
       "3                                    0  \n",
       "4                                    1  \n",
       "5                                    0  \n",
       "6                                    0  \n",
       "7                                    1  \n",
       "8                                   12  \n",
       "9                                    0  \n",
       "10                                   2  \n",
       "11                                   5  \n",
       "12                                   2  \n",
       "13                                  14  \n",
       "14                                   2  \n",
       "15                                   2  \n",
       "16                                   0  \n",
       "17                                   2  \n",
       "18                                  43  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfs[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import urllib3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs2 = pd.read_html('https://www.health.gov.au/news/health-alerts/novel-coronavirus-2019-ncov-health-alert/coronavirus-covid-19-current-situation-and-case-numbers#in-australia/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Location</th>\n",
       "      <th>Confirmed cases*</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>Australian Capital Territory</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>New South Wales</td>\n",
       "      <td>2734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>Northern Territory</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>Queensland</td>\n",
       "      <td>934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>South Australia</td>\n",
       "      <td>415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>Tasmania</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>Victoria</td>\n",
       "      <td>1191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>Western Australia</td>\n",
       "      <td>470</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>Total**</td>\n",
       "      <td>5956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>* Note that under National Notifiable Diseases...</td>\n",
       "      <td>* Note that under National Notifiable Diseases...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            Location  \\\n",
       "0                       Australian Capital Territory   \n",
       "1                                    New South Wales   \n",
       "2                                 Northern Territory   \n",
       "3                                         Queensland   \n",
       "4                                    South Australia   \n",
       "5                                           Tasmania   \n",
       "6                                           Victoria   \n",
       "7                                  Western Australia   \n",
       "8                                            Total**   \n",
       "9  * Note that under National Notifiable Diseases...   \n",
       "\n",
       "                                    Confirmed cases*  \n",
       "0                                                 97  \n",
       "1                                               2734  \n",
       "2                                                 27  \n",
       "3                                                934  \n",
       "4                                                415  \n",
       "5                                                 88  \n",
       "6                                               1191  \n",
       "7                                                470  \n",
       "8                                               5956  \n",
       "9  * Note that under National Notifiable Diseases...  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfs2[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "medals_url = \"http://winterolympicsmedals.com/medals.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "medals_data = pd.read_csv(medals_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>City</th>\n",
       "      <th>Sport</th>\n",
       "      <th>Discipline</th>\n",
       "      <th>NOC</th>\n",
       "      <th>Event</th>\n",
       "      <th>Event gender</th>\n",
       "      <th>Medal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Skating</td>\n",
       "      <td>Figure skating</td>\n",
       "      <td>AUT</td>\n",
       "      <td>individual</td>\n",
       "      <td>M</td>\n",
       "      <td>Silver</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Skating</td>\n",
       "      <td>Figure skating</td>\n",
       "      <td>AUT</td>\n",
       "      <td>individual</td>\n",
       "      <td>W</td>\n",
       "      <td>Gold</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Skating</td>\n",
       "      <td>Figure skating</td>\n",
       "      <td>AUT</td>\n",
       "      <td>pairs</td>\n",
       "      <td>X</td>\n",
       "      <td>Gold</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Bobsleigh</td>\n",
       "      <td>Bobsleigh</td>\n",
       "      <td>BEL</td>\n",
       "      <td>four-man</td>\n",
       "      <td>M</td>\n",
       "      <td>Bronze</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Ice Hockey</td>\n",
       "      <td>Ice Hockey</td>\n",
       "      <td>CAN</td>\n",
       "      <td>ice hockey</td>\n",
       "      <td>M</td>\n",
       "      <td>Gold</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Year      City       Sport      Discipline  NOC       Event Event gender  \\\n",
       "0  1924  Chamonix     Skating  Figure skating  AUT  individual            M   \n",
       "1  1924  Chamonix     Skating  Figure skating  AUT  individual            W   \n",
       "2  1924  Chamonix     Skating  Figure skating  AUT       pairs            X   \n",
       "3  1924  Chamonix   Bobsleigh       Bobsleigh  BEL    four-man            M   \n",
       "4  1924  Chamonix  Ice Hockey      Ice Hockey  CAN  ice hockey            M   \n",
       "\n",
       "    Medal  \n",
       "0  Silver  \n",
       "1    Gold  \n",
       "2    Gold  \n",
       "3  Bronze  \n",
       "4    Gold  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "medals_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "mainpath = \"C:/Users/jgunc/Desktop/DataScience/python-ml-course-master/python-ml-course-master/datasets/python-ml-course/datasets\"\n",
    "filename = \"titanic/titanic3.xls\"\n",
    "filename2 = \"titanic/titanic3.xlsx\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "titanic2 = pd.read_excel ( mainpath + \"/\" + filename, \"titanic3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "titanic3 = pd.read_excel ( mainpath + \"/\" + filename2, \"titanic3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "titanic3.to_csv (mainpath + \"/titanic/titanic_custom.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "titanic3.to_excel(mainpath + \"/titanic/titanic_custom.xls\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "titanic3.to_json(mainpath + \"/titanic/titanic_custom.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "medals_url = \"http://winterolympicsmedals.com/medals.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "medals_data = pd.read_csv(medals_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>City</th>\n",
       "      <th>Sport</th>\n",
       "      <th>Discipline</th>\n",
       "      <th>NOC</th>\n",
       "      <th>Event</th>\n",
       "      <th>Event gender</th>\n",
       "      <th>Medal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Skating</td>\n",
       "      <td>Figure skating</td>\n",
       "      <td>AUT</td>\n",
       "      <td>individual</td>\n",
       "      <td>M</td>\n",
       "      <td>Silver</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Skating</td>\n",
       "      <td>Figure skating</td>\n",
       "      <td>AUT</td>\n",
       "      <td>individual</td>\n",
       "      <td>W</td>\n",
       "      <td>Gold</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Skating</td>\n",
       "      <td>Figure skating</td>\n",
       "      <td>AUT</td>\n",
       "      <td>pairs</td>\n",
       "      <td>X</td>\n",
       "      <td>Gold</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Bobsleigh</td>\n",
       "      <td>Bobsleigh</td>\n",
       "      <td>BEL</td>\n",
       "      <td>four-man</td>\n",
       "      <td>M</td>\n",
       "      <td>Bronze</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1924</td>\n",
       "      <td>Chamonix</td>\n",
       "      <td>Ice Hockey</td>\n",
       "      <td>Ice Hockey</td>\n",
       "      <td>CAN</td>\n",
       "      <td>ice hockey</td>\n",
       "      <td>M</td>\n",
       "      <td>Gold</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Year      City       Sport      Discipline  NOC       Event Event gender  \\\n",
       "0  1924  Chamonix     Skating  Figure skating  AUT  individual            M   \n",
       "1  1924  Chamonix     Skating  Figure skating  AUT  individual            W   \n",
       "2  1924  Chamonix     Skating  Figure skating  AUT       pairs            X   \n",
       "3  1924  Chamonix   Bobsleigh       Bobsleigh  BEL    four-man            M   \n",
       "4  1924  Chamonix  Ice Hockey      Ice Hockey  CAN  ice hockey            M   \n",
       "\n",
       "    Medal  \n",
       "0  Silver  \n",
       "1    Gold  \n",
       "2    Gold  \n",
       "3  Bronze  \n",
       "4    Gold  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "medals_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "def downloadFromURL (url, filename):\n",
    "    #primero importamos la libreria y hacemos la conexion con la BD\n",
    "    import urllib3\n",
    "    http = urllib3.PoolManager ()\n",
    "    r = http.request ('GET', url)\n",
    "    print (\"El estado de la respuesta es %d\" % (r.status))\n",
    "    response = r.data\n",
    "\n",
    "    #El objeto response contiene un string binario , asi que lo convierte a un string decodificandolo en UTF 8\n",
    "    str_data = response.decode('utf-8')\n",
    "\n",
    "    # Dividimos el String en un array de filas\n",
    "    lines = str_data.split(\"\\n\")\n",
    "\n",
    "        #La primera linea contiene la cabecera, asi que se extrae\n",
    "    col_names = lines[0].split(\",\")\n",
    "    n_cols = len(col_names)\n",
    "\n",
    "    # se genera un diccionario vacio\n",
    "    counter = 0\n",
    "    main_dict = {}\n",
    "    for col in col_names:\n",
    "        main_dict[col] = []\n",
    "\n",
    "    #Procesamos Fila a Fila la informacion para ir rellenenado el diccionario con los datos \n",
    "    for line in lines:\n",
    "        # Se salta la cabecra\n",
    "        if(counter > 0):\n",
    "            #Se devide cada string por las comas como elemento separador\n",
    "            values = line.strip().split(\",\")\n",
    "            #Se añade cada valor a su respectiva columna del dccionario\n",
    "            for i in range(len(col_names)):\n",
    "                main_dict[col_names[i]].append(values[i])\n",
    "        counter +=1\n",
    "\n",
    "    print(\"El data set salidas tiene %d filas y %d columnas\"%(counter, n_cols))\n",
    "\n",
    "    #Convertimos el diccionario procesado de data frame \n",
    "    medals_df = pd.DataFrame (main_dict)\n",
    "    print (medals_df.head ())\n",
    "\n",
    "            #Elegimos donde guardarlo\n",
    "\n",
    "    mainpath = \"C:/Users/jgunc/Desktop/DataScience/python-ml-course-master/python-ml-course-master/datasets/python-ml-course/datasets\"\n",
    "    #filename = \"athletes/downloaded_medals\"\n",
    "    fullpath = os.path.join (mainpath , filename)\n",
    "\n",
    "            #Lo guardamos en CSV, JSON y EXCEL\n",
    "\n",
    "    medals_df.to_csv (fullpath+\".csv\")\n",
    "    medals_df.to_json (fullpath+\".json\")\n",
    "    medals_df.to_excel (fullpath+\".xls\")\n",
    "\n",
    "    return\n",
    "    \n",
    "    \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "El estado de la respuesta es 200\n",
      "El data set tiene 2312 filas y 8 columnas\n",
      "   Year      City       Sport      Discipline  NOC       Event Event gender  \\\n",
      "0  1924  Chamonix     Skating  Figure skating  AUT  individual            M   \n",
      "1  1924  Chamonix     Skating  Figure skating  AUT  individual            W   \n",
      "2  1924  Chamonix     Skating  Figure skating  AUT       pairs            X   \n",
      "3  1924  Chamonix   Bobsleigh       Bobsleigh  BEL    four-man            M   \n",
      "4  1924  Chamonix  Ice Hockey      Ice Hockey  CAN  ice hockey            M   \n",
      "\n",
      "    Medal  \n",
      "0  Silver  \n",
      "1    Gold  \n",
      "2    Gold  \n",
      "3  Bronze  \n",
      "4    Gold  \n"
     ]
    }
   ],
   "source": [
    "downloadFromURL (medals_url, \"athletes/downloaded_medals\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
