Reading CSV from Datasette SQL Database
• 2 min read
import pandas as pd
import numpy as np
import datetime
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_csv('https://stocks-snp-500.herokuapp.com/stocks/index_stock.csv?_size=max')
--------------------------------------------------------------------------- HTTPError Traceback (most recent call last) <ipython-input-5-20c2aac4a670> in <module> ----> 1 df = pd.read_csv('https://stocks-snp-500.herokuapp.com/stocks/index_stock.csv?_size=max') ~/dev/Timeseries/timeseries/lib/python3.8/site-packages/pandas/io/parsers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision) 686 ) 687 --> 688 return _read(filepath_or_buffer, kwds) 689 690 ~/dev/Timeseries/timeseries/lib/python3.8/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds) 434 # though mypy handling of conditional imports is difficult. 435 # See https://github.com/python/mypy/issues/1297 --> 436 fp_or_buf, _, compression, should_close = get_filepath_or_buffer( 437 filepath_or_buffer, encoding, compression 438 ) ~/dev/Timeseries/timeseries/lib/python3.8/site-packages/pandas/io/common.py in get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode, storage_options) 181 if isinstance(filepath_or_buffer, str) and is_url(filepath_or_buffer): 182 # TODO: fsspec can also handle HTTP via requests, but leaving this unchanged --> 183 req = urlopen(filepath_or_buffer) 184 content_encoding = req.headers.get("Content-Encoding", None) 185 if content_encoding == "gzip": ~/dev/Timeseries/timeseries/lib/python3.8/site-packages/pandas/io/common.py in urlopen(*args, **kwargs) 135 import urllib.request 136 --> 137 return urllib.request.urlopen(*args, **kwargs) 138 139 /usr/lib/python3.8/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 220 else: 221 opener = _opener --> 222 return opener.open(url, data, timeout) 223 224 def install_opener(opener): /usr/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout) 529 for processor in self.process_response.get(protocol, []): 530 meth = getattr(processor, meth_name) --> 531 response = meth(req, response) 532 533 return response /usr/lib/python3.8/urllib/request.py in http_response(self, request, response) 638 # request was successfully received, understood, and accepted. 639 if not (200 <= code < 300): --> 640 response = self.parent.error( 641 'http', request, response, code, msg, hdrs) 642 /usr/lib/python3.8/urllib/request.py in error(self, proto, *args) 567 if http_err: 568 args = (dict, 'default', 'http_error_default') + orig_args --> 569 return self._call_chain(*args) 570 571 # XXX probably also want an abstract factory that knows when it makes /usr/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 500 for handler in handlers: 501 func = getattr(handler, meth_name) --> 502 result = func(*args) 503 if result is not None: 504 return result /usr/lib/python3.8/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs) 647 class HTTPDefaultErrorHandler(BaseHandler): 648 def http_error_default(self, req, fp, code, msg, hdrs): --> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp) 650 651 class HTTPRedirectHandler(BaseHandler): HTTPError: HTTP Error 404: Not Found
df
rowid | Date | MSFT_stock | ZOOM_stock | SNOW_stock | FXAIX_stock | |
---|---|---|---|---|---|---|
0 | 1 | 2020-01-02 00:00:00.000000 | 158.779999 | 68.800003 | NaN | 112.980003 |
1 | 2 | 2020-01-03 00:00:00.000000 | 158.320007 | 67.620003 | NaN | 112.190002 |
2 | 3 | 2020-01-06 00:00:00.000000 | 157.080002 | 66.629997 | NaN | 112.589996 |
3 | 4 | 2020-01-07 00:00:00.000000 | 159.320007 | 70.290001 | NaN | 112.290001 |
4 | 5 | 2020-01-08 00:00:00.000000 | 158.929993 | 71.809998 | NaN | 112.839996 |
... | ... | ... | ... | ... | ... | ... |
258 | 259 | 2021-01-11 00:00:00.000000 | 218.470001 | 344.980011 | 295.000000 | 131.750000 |
259 | 260 | 2021-01-12 00:00:00.000000 | 216.500000 | 333.200012 | 298.000000 | 131.800003 |
260 | 261 | 2021-01-13 00:00:00.000000 | 214.020004 | 360.000000 | 295.000000 | 132.100006 |
261 | 262 | 2021-01-14 00:00:00.000000 | 215.910004 | 371.000000 | 305.000000 | 131.619995 |
262 | 263 | 2021-01-15 00:00:00.000000 | 213.520004 | 397.709991 | 306.820007 | 130.679993 |
263 rows × 6 columns
df['FXAIX_stock'].plot()
<AxesSubplot:>