8

parent 6b13b5f3
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -450,50 +450,375 @@ ...@@ -450,50 +450,375 @@
"[3357 rows x 2 columns]" "[3357 rows x 2 columns]"
] ]
}, },
"execution_count": 24, "execution_count": 8,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"raw_data = pd.read_csv(data_url, skiprows=44)\n", "raw_data = pd.read_csv(data_file, skiprows=44)\n",
"raw_data" "raw_data"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "ParserError", "data": {
"evalue": "Error tokenizing data. C error: Expected 1 fields in line 33, saw 4\n", "text/html": [
"output_type": "error", "<div>\n",
"traceback": [ "<style scoped>\n",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", " .dataframe tbody tr th:only-of-type {\n",
"\u001b[0;31mParserError\u001b[0m Traceback (most recent call last)", " vertical-align: middle;\n",
"\u001b[0;32m<ipython-input-19-46808fbde0cb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mraw_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_file\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mraw_data\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", " }\n",
"\u001b[0;32m/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36mparser_f\u001b[0;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)\u001b[0m\n\u001b[1;32m 707\u001b[0m skip_blank_lines=skip_blank_lines)\n\u001b[1;32m 708\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 709\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_read\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilepath_or_buffer\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 710\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 711\u001b[0m \u001b[0mparser_f\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\n",
"\u001b[0;32m/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m_read\u001b[0;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[1;32m 453\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 454\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 455\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnrows\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 456\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 457\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", " .dataframe tbody tr th {\n",
"\u001b[0;32m/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(self, nrows)\u001b[0m\n\u001b[1;32m 1067\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'skipfooter not supported for iteration'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1068\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1069\u001b[0;31m \u001b[0mret\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnrows\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1070\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1071\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'as_recarray'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", " vertical-align: top;\n",
"\u001b[0;32m/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(self, nrows)\u001b[0m\n\u001b[1;32m 1837\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnrows\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1838\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1839\u001b[0;31m \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_reader\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnrows\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1840\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1841\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_first_chunk\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", " }\n",
"\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader.read\u001b[0;34m()\u001b[0m\n", "\n",
"\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader._read_low_memory\u001b[0;34m()\u001b[0m\n", " .dataframe thead th {\n",
"\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader._read_rows\u001b[0;34m()\u001b[0m\n", " text-align: right;\n",
"\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader._tokenize_rows\u001b[0;34m()\u001b[0m\n", " }\n",
"\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.raise_parser_error\u001b[0;34m()\u001b[0m\n", "</style>\n",
"\u001b[0;31mParserError\u001b[0m: Error tokenizing data. C error: Expected 1 fields in line 33, saw 4\n" "<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>indicated by the date in the first column.</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1958-03-29</th>\n",
" <td>316.19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-04-05</th>\n",
" <td>317.31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-04-12</th>\n",
" <td>317.69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-04-19</th>\n",
" <td>317.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-04-26</th>\n",
" <td>316.48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-05-03</th>\n",
" <td>316.95</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-05-17</th>\n",
" <td>317.56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-05-24</th>\n",
" <td>317.99</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-07-05</th>\n",
" <td>315.85</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-07-12</th>\n",
" <td>315.85</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-07-19</th>\n",
" <td>315.46</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-07-26</th>\n",
" <td>315.59</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-08-02</th>\n",
" <td>315.64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-08-09</th>\n",
" <td>315.10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-08-16</th>\n",
" <td>315.09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-08-30</th>\n",
" <td>314.14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-09-06</th>\n",
" <td>313.54</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-11-08</th>\n",
" <td>313.05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-11-15</th>\n",
" <td>313.26</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-11-22</th>\n",
" <td>313.57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-11-29</th>\n",
" <td>314.01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-12-06</th>\n",
" <td>314.56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-12-13</th>\n",
" <td>314.41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-12-20</th>\n",
" <td>314.77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1958-12-27</th>\n",
" <td>315.21</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1959-01-03</th>\n",
" <td>315.24</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1959-01-10</th>\n",
" <td>315.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1959-01-17</th>\n",
" <td>315.69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1959-01-24</th>\n",
" <td>315.86</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1959-01-31</th>\n",
" <td>315.42</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-06-10</th>\n",
" <td>424.01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-06-17</th>\n",
" <td>422.93</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-06-24</th>\n",
" <td>422.21</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-07-01</th>\n",
" <td>422.80</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-07-08</th>\n",
" <td>422.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-07-15</th>\n",
" <td>421.43</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-07-22</th>\n",
" <td>420.74</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-07-29</th>\n",
" <td>420.88</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-08-05</th>\n",
" <td>420.39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-08-12</th>\n",
" <td>420.30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-08-19</th>\n",
" <td>418.96</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-08-26</th>\n",
" <td>418.84</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-09-02</th>\n",
" <td>418.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-09-09</th>\n",
" <td>418.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-09-16</th>\n",
" <td>418.52</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-09-23</th>\n",
" <td>417.77</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-09-30</th>\n",
" <td>417.89</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-10-07</th>\n",
" <td>418.10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-10-14</th>\n",
" <td>418.82</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-10-21</th>\n",
" <td>418.85</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-10-28</th>\n",
" <td>418.62</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-11-04</th>\n",
" <td>419.07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-11-11</th>\n",
" <td>419.41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-11-18</th>\n",
" <td>421.18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-11-25</th>\n",
" <td>421.22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-02</th>\n",
" <td>420.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-09</th>\n",
" <td>421.23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-16</th>\n",
" <td>422.57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-23</th>\n",
" <td>422.06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2023-12-30</th>\n",
" <td>421.76</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3358 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" indicated by the date in the first column. \n",
"1958-03-29 316.19 \n",
"1958-04-05 317.31 \n",
"1958-04-12 317.69 \n",
"1958-04-19 317.58 \n",
"1958-04-26 316.48 \n",
"1958-05-03 316.95 \n",
"1958-05-17 317.56 \n",
"1958-05-24 317.99 \n",
"1958-07-05 315.85 \n",
"1958-07-12 315.85 \n",
"1958-07-19 315.46 \n",
"1958-07-26 315.59 \n",
"1958-08-02 315.64 \n",
"1958-08-09 315.10 \n",
"1958-08-16 315.09 \n",
"1958-08-30 314.14 \n",
"1958-09-06 313.54 \n",
"1958-11-08 313.05 \n",
"1958-11-15 313.26 \n",
"1958-11-22 313.57 \n",
"1958-11-29 314.01 \n",
"1958-12-06 314.56 \n",
"1958-12-13 314.41 \n",
"1958-12-20 314.77 \n",
"1958-12-27 315.21 \n",
"1959-01-03 315.24 \n",
"1959-01-10 315.50 \n",
"1959-01-17 315.69 \n",
"1959-01-24 315.86 \n",
"1959-01-31 315.42 \n",
"... ... \n",
"2023-06-10 424.01 \n",
"2023-06-17 422.93 \n",
"2023-06-24 422.21 \n",
"2023-07-01 422.80 \n",
"2023-07-08 422.32 \n",
"2023-07-15 421.43 \n",
"2023-07-22 420.74 \n",
"2023-07-29 420.88 \n",
"2023-08-05 420.39 \n",
"2023-08-12 420.30 \n",
"2023-08-19 418.96 \n",
"2023-08-26 418.84 \n",
"2023-09-02 418.50 \n",
"2023-09-09 418.28 \n",
"2023-09-16 418.52 \n",
"2023-09-23 417.77 \n",
"2023-09-30 417.89 \n",
"2023-10-07 418.10 \n",
"2023-10-14 418.82 \n",
"2023-10-21 418.85 \n",
"2023-10-28 418.62 \n",
"2023-11-04 419.07 \n",
"2023-11-11 419.41 \n",
"2023-11-18 421.18 \n",
"2023-11-25 421.22 \n",
"2023-12-02 420.28 \n",
"2023-12-09 421.23 \n",
"2023-12-16 422.57 \n",
"2023-12-23 422.06 \n",
"2023-12-30 421.76 \n",
"\n",
"[3358 rows x 1 columns]"
] ]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"raw_data = pd.read_csv(data_file)\n", "raw_data = pd.read_csv(data_file, skiprows=43)\n",
"raw_data" "raw_data"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -746,7 +1071,7 @@ ...@@ -746,7 +1071,7 @@
"41 indicated by the date in the first column. ... " "41 indicated by the date in the first column. ... "
] ]
}, },
"execution_count": 20, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -758,20 +1083,20 @@ ...@@ -758,20 +1083,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
" 316.19\n", " indicated by the date in the.1 first column. \".1\n",
"1958-03-29, \n", "\" \n",
"1958-04-05 317.31\n", "1958-03-29 316.19 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"1958-04-12 317.69\n", "1958-04-05 317.31 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"1958-04-19 317.58\n", "1958-04-12 317.69 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"1958-04-26 316.48\n", "1958-04-19 317.58 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"1958-05-03 316.95\n" "1958-04-26 316.48 NaN NaN NaN NaN NaN NaN NaN NaN\n"
] ]
} }
], ],
...@@ -786,7 +1111,7 @@ ...@@ -786,7 +1111,7 @@
"if not os.path.exists(data_file):\n", "if not os.path.exists(data_file):\n",
" urllib.request.urlretrieve(file_path, data_file_co2)\n", " urllib.request.urlretrieve(file_path, data_file_co2)\n",
"\n", "\n",
"data_co2 = pd.read_csv(file_path, skiprows=44, sep=r'\\s+', engine='python', parse_dates=[0], index_col=[0])\n", "data_co2 = pd.read_csv(file_path, skiprows=43, sep=r'\\s+', engine='python', parse_dates=[0], index_col=[0])\n",
"\n", "\n",
"# Verificar los primeros registros de datos\n", "# Verificar los primeros registros de datos\n",
"print(data_co2.head())" "print(data_co2.head())"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment