Skip to content

Instantly share code, notes, and snippets.

@cameronShadmehry
Created July 1, 2020 04:40
Show Gist options
  • Save cameronShadmehry/25171c3bd7a311a3e57bcd5283d1b90e to your computer and use it in GitHub Desktop.
Save cameronShadmehry/25171c3bd7a311a3e57bcd5283d1b90e to your computer and use it in GitHub Desktop.
Code to select the list of tickers we want to analyze.
# List of the stocks we are interested in analyzing. At the time of writing this, it narrows the list of stocks down to 44. If you have a list of your own you would like to use just create a new list instead of using this, for example: tickers = ["FB", "AMZN", ...]
tickers = gt.get_tickers_filtered(mktcap_min=150000, mktcap_max=10000000)
# Check that the amount of tickers isn't more than 1800
print("The amount of stocks chosen to observe: " + str(len(tickers)))
@yusif2e2simaan
Copy link

I ran line 2 after importing all packages suggested. I get the following error

ParserError Traceback (most recent call last)
in
----> 1 tickers = gt.get_tickers_filtered(mktcap_min=150000, mktcap_max=10000000)

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/get_all_tickers/get_tickers.py in get_tickers_filtered(mktcap_min, mktcap_max, sectors)
82 tickers_list = []
83 for exchange in _EXCHANGE_LIST:
---> 84 tickers_list.extend(__exchange2list_filtered(exchange, mktcap_min=mktcap_min, mktcap_max=mktcap_max, sectors=sectors))
85 return tickers_list
86

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/get_all_tickers/get_tickers.py in __exchange2list_filtered(exchange, mktcap_min, mktcap_max, sectors)
143 # market caps are in millions
144 def __exchange2list_filtered(exchange, mktcap_min=None, mktcap_max=None, sectors=None):
--> 145 df = __exchange2df(exchange)
146 df = df.dropna(subset={'MarketCap'})
147 df = df[~df['Symbol'].str.contains(".|^")]

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/get_all_tickers/get_tickers.py in __exchange2df(exchange)
132 response = requests.get('https://old.nasdaq.com/screening/companies-by-name.aspx', headers=headers, params=params(exchange))
133 data = io.StringIO(response.text)
--> 134 df = pd.read_csv(data, sep=",")
135 return df
136

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/pandas/io/parsers.py in parser_f(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)
674 )
675
--> 676 return _read(filepath_or_buffer, kwds)
677
678 parser_f.name = name

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
452
453 try:
--> 454 data = parser.read(nrows)
455 finally:
456 parser.close()

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/pandas/io/parsers.py in read(self, nrows)
1131 def read(self, nrows=None):
1132 nrows = _validate_integer("nrows", nrows)
-> 1133 ret = self._engine.read(nrows)
1134
1135 # May alter columns / col_dict

~/opt/miniconda3/envs/yes/lib/python3.8/site-packages/pandas/io/parsers.py in read(self, nrows)
2035 def read(self, nrows=None):
2036 try:
-> 2037 data = self._reader.read(nrows)
2038 except StopIteration:
2039 if self._first_chunk:

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.read()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_low_memory()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_rows()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows()

pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()

ParserError: Error tokenizing data. C error: Expected 1 fields in line 23, saw 46

@johnr1044
Copy link

hope someone finds how to fix this I ran into the same error and using PyCharm was able to import most libraries but wouldn't take all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment