Statement of Completion#e6349fbf
Advanced collections
easy
List Comprehensions Practice
Resolution
Activities
In [1]:
import numpy as np
import pandas as pd
Datasets¶
First, start by looking at the data we'll use for our List Comprehension exercises. The data comes from CSV
s that we parse into Lists.
In [2]:
# this is just to show you the structure of the data
# we'll be working with
pd.read_csv('taylor.csv', index_col=0).head()
Out[2]:
x | |
---|---|
1 | 22262 |
2 | 21756 |
3 | 22247 |
4 | 22759 |
5 | 22549 |
In [5]:
electricity_demand = list(pd.read_csv('taylor.csv', index_col=0).squeeze("columns").values)
electricity_demand[:10]
Out[5]:
[22262, 21756, 22247, 22759, 22549, 22313, 22128, 21860, 21751, 21336]
Dataset 2: S&P Companies¶
Companies in the S&P500 index. This is not comprehensive as the data is from 2018 and some might have changed.
We'll read the list in the variable sp_companies
.
In [6]:
pd.read_csv('sp_companies.csv').head()
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) Cell In[6], line 1 ----> 1 pd.read_csv('sp_companies.csv').head() File /usr/local/lib/python3.11/site-packages/pandas/io/parsers/readers.py:912, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, 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, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend) 899 kwds_defaults = _refine_defaults_read( 900 dialect, 901 delimiter, (...) 908 dtype_backend=dtype_backend, 909 ) 910 kwds.update(kwds_defaults) --> 912 return _read(filepath_or_buffer, kwds) File /usr/local/lib/python3.11/site-packages/pandas/io/parsers/readers.py:577, in _read(filepath_or_buffer, kwds) 574 _validate_names(kwds.get("names", None)) 576 # Create the parser. --> 577 parser = TextFileReader(filepath_or_buffer, **kwds) 579 if chunksize or iterator: 580 return parser File /usr/local/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1407, in TextFileReader.__init__(self, f, engine, **kwds) 1404 self.options["has_index_names"] = kwds["has_index_names"] 1406 self.handles: IOHandles | None = None -> 1407 self._engine = self._make_engine(f, self.engine) File /usr/local/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1661, in TextFileReader._make_engine(self, f, engine) 1659 if "b" not in mode: 1660 mode += "b" -> 1661 self.handles = get_handle( 1662 f, 1663 mode, 1664 encoding=self.options.get("encoding", None), 1665 compression=self.options.get("compression", None), 1666 memory_map=self.options.get("memory_map", False), 1667 is_text=is_text, 1668 errors=self.options.get("encoding_errors", "strict"), 1669 storage_options=self.options.get("storage_options", None), 1670 ) 1671 assert self.handles is not None 1672 f = self.handles.handle File /usr/local/lib/python3.11/site-packages/pandas/io/common.py:859, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options) 854 elif isinstance(handle, str): 855 # Check whether the filename is to be opened in binary mode. 856 # Binary mode does not support 'encoding' and 'newline'. 857 if ioargs.encoding and "b" not in ioargs.mode: 858 # Encoding --> 859 handle = open( 860 handle, 861 ioargs.mode, 862 encoding=ioargs.encoding, 863 errors=errors, 864 newline="", 865 ) 866 else: 867 # Binary mode 868 handle = open(handle, ioargs.mode) FileNotFoundError: [Errno 2] No such file or directory: 'sp_companies.csv'
In [7]:
# this is just to show you the structure of the data
# we'll be working with
pd.read_csv('sp500.csv', usecols=['Name']).head()
Out[7]:
Name | |
---|---|
0 | A |
1 | AAL |
2 | AAP |
3 | AAPL |
4 | ABBV |
In [8]:
sp_companies = list(pd.read_csv('sp500.csv', usecols=['Name']).squeeze("columns").values)
sp_companies[:10]
Out[8]:
['A', 'AAL', 'AAP', 'AAPL', 'ABBV', 'ABC', 'ABT', 'ACN', 'ADBE', 'ADI']
Dataset 3: S&P Companies Stock Price¶
This is going to be a list of tuples, containing the ticker of the company and their latest recorded stock price (for February 2018). In the form: [(ticker, price), (ticker, price), ...]
We'll read the list in the variable sp_prices
.
In [9]:
# this is just to show you the structure of the data
# we'll be working with
pd.read_csv('sp500.csv').head(5)
Out[9]:
Name | Price | |
---|---|---|
0 | A | 68.06 |
1 | AAL | 51.40 |
2 | AAP | 109.93 |
3 | AAPL | 159.54 |
4 | ABBV | 113.62 |
In [10]:
sp_prices = [(row['Name'], row['Price']) for idx, row in pd.read_csv('sp500.csv').iterrows()]
sp_prices[:10]
Out[10]:
[('A', 68.06), ('AAL', 51.4), ('AAP', 109.93), ('AAPL', 159.54), ('ABBV', 113.62), ('ABC', 94.22), ('ABT', 58.67), ('ACN', 155.15), ('ADBE', 192.34), ('ADI', 85.35)]
Activities¶
Use the following cells to complete the activities.
1. Lower-case all the companies in sp_companies
¶
In [12]:
sp_companies[:5]
Out[12]:
['A', 'AAL', 'AAP', 'AAPL', 'ABBV']
In [11]:
[comp.lower() for comp in sp_companies]
Out[11]:
['a', 'aal', 'aap', 'aapl', 'abbv', 'abc', 'abt', 'acn', 'adbe', 'adi', 'adm', 'adp', 'ads', 'adsk', 'aee', 'aep', 'aes', 'aet', 'afl', 'agn', 'aig', 'aiv', 'aiz', 'ajg', 'akam', 'alb', 'algn', 'alk', 'all', 'alle', 'alxn', 'amat', 'amd', 'ame', 'amg', 'amgn', 'amp', 'amt', 'amzn', 'andv', 'anss', 'antm', 'aon', 'aos', 'apa', 'apc', 'apd', 'aph', 'aptv', 'are', 'arnc', 'atvi', 'avb', 'avgo', 'avy', 'awk', 'axp', 'ayi', 'azo', 'ba', 'bac', 'bax', 'bbt', 'bby', 'bdx', 'ben', 'bf.b', 'bhf', 'bhge', 'biib', 'bk', 'blk', 'bll', 'bmy', 'brk.b', 'bsx', 'bwa', 'bxp', 'c', 'ca', 'cag', 'cah', 'cat', 'cb', 'cbg', 'cboe', 'cbs', 'cci', 'ccl', 'cdns', 'celg', 'cern', 'cf', 'cfg', 'chd', 'chk', 'chrw', 'chtr', 'ci', 'cinf', 'cl', 'clx', 'cma', 'cmcsa', 'cme', 'cmg', 'cmi', 'cms', 'cnc', 'cnp', 'cof', 'cog', 'col', 'coo', 'cop', 'cost', 'coty', 'cpb', 'crm', 'csco', 'csra', 'csx', 'ctas', 'ctl', 'ctsh', 'ctxs', 'cvs', 'cvx', 'cxo', 'd', 'dal', 'de', 'dfs', 'dg', 'dgx', 'dhi', 'dhr', 'dis', 'disca', 'disck', 'dish', 'dlr', 'dltr', 'dov', 'dps', 'dre', 'dri', 'dte', 'duk', 'dva', 'dvn', 'dwdp', 'dxc', 'ea', 'ebay', 'ecl', 'ed', 'efx', 'eix', 'el', 'emn', 'emr', 'eog', 'eqix', 'eqr', 'eqt', 'es', 'esrx', 'ess', 'etfc', 'etn', 'etr', 'evhc', 'ew', 'exc', 'expd', 'expe', 'exr', 'f', 'fast', 'fb', 'fbhs', 'fcx', 'fdx', 'fe', 'ffiv', 'fis', 'fisv', 'fitb', 'fl', 'flir', 'flr', 'fls', 'fmc', 'fox', 'foxa', 'frt', 'fti', 'ftv', 'gd', 'ge', 'ggp', 'gild', 'gis', 'glw', 'gm', 'goog', 'googl', 'gpc', 'gpn', 'gps', 'grmn', 'gs', 'gt', 'gww', 'hal', 'has', 'hban', 'hbi', 'hca', 'hcn', 'hcp', 'hd', 'hes', 'hig', 'hii', 'hlt', 'hog', 'holx', 'hon', 'hp', 'hpe', 'hpq', 'hrb', 'hrl', 'hrs', 'hsic', 'hst', 'hsy', 'hum', 'ibm', 'ice', 'idxx', 'iff', 'ilmn', 'incy', 'info', 'intc', 'intu', 'ip', 'ipg', 'iqv', 'ir', 'irm', 'isrg', 'it', 'itw', 'ivz', 'jbht', 'jci', 'jec', 'jnj', 'jnpr', 'jpm', 'jwn', 'k', 'key', 'khc', 'kim', 'klac', 'kmb', 'kmi', 'kmx', 'ko', 'kors', 'kr', 'kss', 'ksu', 'l', 'lb', 'leg', 'len', 'lh', 'lkq', 'lll', 'lly', 'lmt', 'lnc', 'lnt', 'low', 'lrcx', 'luk', 'luv', 'lyb', 'm', 'ma', 'maa', 'mac', 'mar', 'mas', 'mat', 'mcd', 'mchp', 'mck', 'mco', 'mdlz', 'mdt', 'met', 'mgm', 'mhk', 'mkc', 'mlm', 'mmc', 'mmm', 'mnst', 'mo', 'mon', 'mos', 'mpc', 'mrk', 'mro', 'ms', 'msft', 'msi', 'mtb', 'mtd', 'mu', 'myl', 'navi', 'nbl', 'nclh', 'ndaq', 'nee', 'nem', 'nflx', 'nfx', 'ni', 'nke', 'nlsn', 'noc', 'nov', 'nrg', 'nsc', 'ntap', 'ntrs', 'nue', 'nvda', 'nwl', 'nws', 'nwsa', 'o', 'oke', 'omc', 'orcl', 'orly', 'oxy', 'payx', 'pbct', 'pcar', 'pcg', 'pcln', 'pdco', 'peg', 'pep', 'pfe', 'pfg', 'pg', 'pgr', 'ph', 'phm', 'pkg', 'pki', 'pld', 'pm', 'pnc', 'pnr', 'pnw', 'ppg', 'ppl', 'prgo', 'pru', 'psa', 'psx', 'pvh', 'pwr', 'px', 'pxd', 'pypl', 'qcom', 'qrvo', 'rcl', 're', 'reg', 'regn', 'rf', 'rhi', 'rht', 'rjf', 'rl', 'rmd', 'rok', 'rop', 'rost', 'rrc', 'rsg', 'rtn', 'sbac', 'sbux', 'scg', 'schw', 'see', 'shw', 'sig', 'sjm', 'slb', 'slg', 'sna', 'sni', 'snps', 'so', 'spg', 'spgi', 'srcl', 'sre', 'sti', 'stt', 'stx', 'stz', 'swk', 'swks', 'syf', 'syk', 'symc', 'syy', 't', 'tap', 'tdg', 'tel', 'tgt', 'tif', 'tjx', 'tmk', 'tmo', 'tpr', 'trip', 'trow', 'trv', 'tsco', 'tsn', 'tss', 'twx', 'txn', 'txt', 'ua', 'uaa', 'ual', 'udr', 'uhs', 'ulta', 'unh', 'unm', 'unp', 'ups', 'uri', 'usb', 'utx', 'v', 'var', 'vfc', 'viab', 'vlo', 'vmc', 'vno', 'vrsk', 'vrsn', 'vrtx', 'vtr', 'vz', 'wat', 'wba', 'wdc', 'wec', 'wfc', 'whr', 'wltw', 'wm', 'wmb', 'wmt', 'wrk', 'wu', 'wy', 'wyn', 'wynn', 'xec', 'xel', 'xl', 'xlnx', 'xom', 'xray', 'xrx', 'xyl', 'yum', 'zbh', 'zion', 'zts']
2. Standarize all the values in electricity_demand
¶
In [13]:
np.mean(electricity_demand)
Out[13]:
29617.136160714286
In [14]:
np.std(electricity_demand)
Out[14]:
5566.669346535028
In [17]:
[(sample - 29617)/ 5566 for sample in electricity_demand]
Out[17]:
[-1.321415738411786, -1.4123248293208768, -1.3241106719367588, -1.2321236076176787, -1.2698526769673015, -1.3122529644268774, -1.345490477901545, -1.3936399568810636, -1.4132231404958677, -1.4877829680201222, -1.4829320876751706, -1.3368666906216313, -0.8925619834710744, -0.38645346748113546, 0.25206611570247933, 0.7028386633129716, 1.04401724757456, 1.1528925619834711, 1.2966223499820337, 1.3796263025512037, 1.3871721164211284, 1.4356809198706433, 1.4507725476104922, 1.4960474308300395, 1.4845490477901546, 1.4150197628458498, 1.3381243262666187, 1.300395256916996, 1.3032698526769673, 1.2971613366870285, 1.2551203736974488, 1.3232123607617678, 1.3927416457060726, 1.4432267337405678, 1.4006467840459935, 1.2321236076176787, 1.0544376572044556, 0.8686669062163134, 0.7342795544376572, 0.5867768595041323, 0.41735537190082644, 0.46676248652533237, 0.530901904419691, 0.5808480057491915, 0.4732303269852677, 0.22960833632770392, -0.20786920589292132, -0.5470715055695293, -0.8127919511318721, -0.9516708587854833, -0.8862738052461373, -0.7687747035573123, -0.8397412863816026, -0.8947179302910528, -0.9329859863456701, -0.9798778296802012, -1.019403521379806, -1.1306144448436939, -1.1148041681638519, -0.9974847287100251, -0.6435501257635645, -0.17696730147323034, 0.43226733740567735, 0.8440531800215595, 1.1336687028386634, 1.2127200862378729, 1.3420768954365792, 1.359504132231405, 1.3280632411067195, 1.3645346748113547, 1.4218469277757815, 1.4863456701401365, 1.5028745957599712, 1.4234638878907653, 1.355192238591448, 1.3120733021918793, 1.3372260150916278, 1.3138699245418612, 1.2617678763923823, 1.3102766798418972, 1.3659719726913402, 1.4216672655407834, 1.3839381961911605, 1.2062522457779374, 1.0041322314049588, 0.8239310097017607, 0.6568451311534316, 0.4956881063600431, 0.3990298239310097, 0.2863816025871362, 0.339202299676608, 0.3990298239310097, 0.46137261947538627, 0.22709306503772908, -0.14678404599353215, -0.5001796622349982, -0.8124326266618757, -0.9306503772906934, -0.8839381961911607, -0.7829680201221704, -0.8242903341717571, -0.8643550125763565, -0.9306503772906934, -0.9590370104204097, -1.0267696730147322, -1.1137261947538628, -1.1126482213438735, -0.9922745238950773, -0.6428314768235717, -0.17624865253323752, 0.4342436219906576, 0.8296802012217032, 1.091807402084082, 1.1428314768235717, 1.2321236076176787, 1.2680560546173194, 1.2761408551922386, 1.2980596478620194, 1.3066834351419332, 1.3115343154868846, 1.3002155946819978, 1.2411067193675889, 1.2242184692777578, 1.1848724398131514, 1.1577434423284225, 1.134387351778656, 1.1171397772188285, 1.1733740567732662, 1.2407473948975924, 1.301113905856989, 1.2781171397772189, 1.1115702479338843, 0.9169960474308301, 0.7937477542220626, 0.6498383039885016, 0.5237154150197628, 0.33363277039166367, 0.4204096298957959, 0.5179662234998204, 0.5334171757096658, 0.4132231404958678, 0.18307581746316925, -0.16385195831836147, -0.5228171038447719, -0.8129716133668703, -0.9351419331656485, -0.8808839381961912, -0.8153072224218469, -0.8467481135465326, -0.9408911246855911, -1.0075458138699245, -1.024793388429752, -1.0707869205892921, -1.1417535034135824, -1.1379805964786203, -1.0325188645346748, -0.6496586417535034, -0.21002515271289976, 0.4058569888609414, 0.8526769673014732, 1.1142651814588573, 1.1997844053180022, 1.3172835070068272, 1.3435141933165649, 1.341897233201581, 1.4198706431908013, 1.4234638878907653, 1.44699964067553, 1.451311534315487, 1.3828602227811715, 1.3467481135465325, 1.2897951850521021, 1.2734459216672656, 1.260689902982393, 1.2109234638878907, 1.2660797700323392, 1.3300395256916997, 1.3537549407114624, 1.2969816744520302, 1.1482213438735178, 0.9637082285303629, 0.8350700682716493, 0.6769673014732304, 0.5138339920948617, 0.42202659001077975, 0.32069708947179304, 0.37477542220625226, 0.4626302551203737, 0.48598634567014015, 0.24344232842256558, -0.12702120014372978, -0.4716133668702839, -0.7712899748472871, -0.8862738052461373, -0.8487243981315128, -0.8129716133668703, -0.8742364355012576, -0.9664031620553359, -1.0260510240747396, -1.0531800215594682, -1.0765361121092347, -1.1839741286381602, -1.171397772188286, -1.064498742364355, -0.6613366870283867, -0.20050305425799497, 0.3990298239310097, 0.842795544376572, 1.2015810276679841, 1.2802730865971972, 1.4531081566654689, 1.5025152712899748, 1.521200143729788, 1.574200503054258, 1.6006108515989939, 1.5831836148041682, 1.567912324829321, 1.4674811354653252, 1.4153790873158463, 1.3605821056413943, 1.3282429033417176, 1.2619475386273806, 1.1999640675530003, 1.202299676607977, 1.2423643550125762, 1.2657204455623428, 1.1879266978081207, 1.024793388429752, 0.8609414301113906, 0.6841537908731584, 0.5553359683794467, 0.3311174991016888, 0.2403880704275961, 0.11803808839381962, 0.12306863097376931, 0.14552641034854474, 0.09647862019403522, -0.054976643909450236, -0.34459216672655407, -0.6115702479338843, -0.8733381243262667, -1.0366510959396336, -1.0240747394897594, -1.0111390585698885, -1.089112468559109, -1.1841537908731585, -1.2484728710025152, -1.2874595759971255, -1.3740567732662594, -1.5100610851598995, -1.552102048149479, -1.520301832554797, -1.30201221703198, -1.0923463887890765, -0.7917714696370823, -0.4771828961552282, -0.15217391304347827, 0.053539346029464606, 0.22960833632770392, 0.2975206611570248, 0.3185411426518146, 0.30003593244699966, 0.27775781530722243, 0.21451670858785482, 0.12450592885375494, 0.026949335249730505, -0.10797700323392023, -0.22332015810276679, -0.27901545095220986, -0.3625583902263744, -0.4094502335609055, -0.44214876033057854, -0.40639597556593604, -0.3156665468918433, -0.2339202299676608, -0.21936758893280633, -0.3027308659719727, -0.33075817463169244, -0.3767517067912325, -0.46550485088034493, -0.5332375134746676, -0.5882141573841179, -0.5623427955443766, -0.4308300395256917, -0.40118577075098816, -0.5276679841897233, -0.7112827883578872, -0.9628099173553719, -1.2132590729428674, -1.3688465684513116, -1.3388429752066116, -1.3131512756018684, -1.393100970176069, -1.4692777578153071, -1.5361121092346388, -1.5874955084441251, -1.6579231045634208, -1.7883578871721164, -1.8526769673014731, -1.8338124326266618, -1.7136183974128638, -1.6018684872439812, -1.4333453108156666, -1.2387711103126122, -1.000898311174991, -0.8025512037369745, -0.5986345670140136, -0.39471793029105284, -0.21182177506288177, -0.15217391304347827, -0.05533596837944664, -0.005569529284944304, 0.018684872439813153, -0.003413582464965864, -0.15109593963348905, -0.28907653611210926, -0.3826805605461732, -0.4213079410707869, -0.45382680560546174, -0.44214876033057854, -0.4360402443406396, -0.38735177865612647, -0.3404599353215954, -0.36543298598634566, -0.3668702838663313, -0.37818900467121813, -0.3618397412863816, -0.4423284225655767, -0.4252605102407474, -0.4342436219906576, -0.32680560546173193, -0.2030183255479698, -0.16636722960833633, -0.42346388789076533, -0.7628458498023716, -1.0650377290693496, -1.2869205892921307, -1.401185770750988, -1.3681279195113187, -1.2757815307222422, -1.3160258713618398, -1.3801652892561984, -1.4254401724757455, -1.4302910528206971, -1.4617319439453826, -1.52299676607977, -1.492813510600072, -1.343693855551563, -0.8835788717211642, -0.4044196909809558, 0.2436219906575638, 0.6970894717930292, 1.0016169601149838, 1.0792310456342078, 1.2265540783327344, 1.3090190441969098, 1.3163851958318362, 1.366510959396335, 1.3884297520661157, 1.4540064678404598, 1.441609773625584, 1.396694214876033, 1.3472871002515272, 1.329500538986705, 1.3307581746316923, 1.3052461372619475, 1.2554796981674452, 1.3014732303269854, 1.3697448796263025, 1.4252605102407474, 1.3650736615163492, 1.1832554796981674, 0.9734099892202659, 0.8075817463169241, 0.6943945382680561, 0.4908372260150916, 0.2818900467121811, 0.234099892202659, 0.11731943945382681, 0.404599353215954, 0.36543298598634566, 0.21631333093783686, -0.1956521739130435, -0.5285662953647143, -0.8063241106719368, -0.932806324110672, -0.912504491555875, -0.905497664390945, -0.9705353934602946, -1.00700682716493, -1.0589292130794108, -1.0907294286740927, -1.1207330219187928, -1.2145167085878548, -1.1997844053180022, -1.1054617319439455, -0.6976284584980237, -0.24739489759252606, 0.3562702120014373, 0.7894358605821057, 1.06899029823931, 1.137082285303629, 1.2784764642472153, 1.319798778296802, 1.3280632411067195, 1.3444125044915558, 1.3740567732662594, 1.4123248293208768, 1.4094502335609056, 1.3336327703916637, 1.2865612648221343, 1.2687747035573123, 1.249191519942508, 1.2382321236076177, 1.2245777937477542, 1.2779374775422205, 1.348904060366511, 1.3909450233560905, 1.3255479698167445, 1.1735537190082646, 0.9392741645706073, 0.7849443047071506, 0.6712181099532878, 0.5350341358246496, 0.39813151275601866, 0.31710384477182896, 0.29590370104204095, 0.393100970176069, 0.44017247574559826, 0.19870643190801293, -0.1582824290334172, -0.5061085159899389, -0.7763205174272368, -0.8992094861660079, -0.8988501616960115, -0.8835788717211642, -0.9448436938555516, -1.0217391304347827, -1.0648580668343515, -1.0594681997844053, -1.1040244340639598, -1.1469637082285304, -1.1212720086237873, -1.024793388429752, -0.6449874236435501, -0.1753503413582465, 0.44484369385555156, 0.8948975925260511, 1.16798418972332, 1.2375134746676248, 1.3794466403162056, 1.4274164570607257, 1.4245418613007546, 1.4583183614804167, 1.5188645346748113, 1.5427596119295723, 1.5479698167445204, 1.4540064678404598, 1.4089112468559108, 1.366690621631333, 1.3638160258713619, 1.3196191160618038, 1.2971613366870285, 1.3535752784764643, 1.434602946460654, 1.5159899389148401, 1.4665828242903343, 1.2962630255120373, 1.1218109953287818, 1.003413582464966, 0.849802371541502, 0.7087675170679123, 0.5826446280991735, 0.5370104204096299, 0.5319798778296801, 0.527308659719727, 0.4741286381602587, 0.22924901185770752, -0.11875673733381244, -0.4834710743801653, -0.768595041322314, -0.8875314408911247, -0.870104204096299, -0.8417175709665828, -0.8986704994610133, -0.9653251886453468, -1.0159899389148401, -1.0145526410348544, -1.0767157743442328, -1.1685231764283148, -1.1491196550485088, -1.0199425080848006, -0.61300754581387, -0.1859504132231405, 0.4311893639956881, 0.8896873877111031, 1.1766079770032338, 1.2384117858426158, 1.3713618397412863, 1.3932806324110671, 1.3835788717211641, 1.3862738052461372, 1.4362199065756378, 1.4586776859504131, 1.4622709306503774, 1.3758533956162415, 1.3282429033417176, 1.3131512756018684, 1.2971613366870285, 1.277218828602228, 1.2274523895077254, 1.2786561264822134, 1.3384836507366151, 1.3577075098814229, 1.2948257276320518, 1.143190801293568, 0.9586776859504132, 0.8296802012217032, 0.6706791232482933, 0.5474308300395256, 0.414301113905857, 0.3568091987064319, 0.38070427596119294, 0.4522098454904779, 0.4268774703557312, 0.24056773266259432, -0.13582464965864174, -0.4680201221703198, -0.7815307222421847, -0.9085519223859145, -0.934602946460654, -0.9211282788357887, -0.9989220265900107, -1.0666546891843334, -1.1097736255839024, -1.1112109234638878, -1.1557671577434423, -1.2294286740927056, -1.201401365432986, -1.084800574919152, -0.68199784405318, -0.2558390226374416, 0.36471433704635287, 0.8084800574919152, 1.0731225296442688, 1.1767876392382322, 1.2799137621272008, 1.2847646424721524, 1.2874595759971255, 1.3248293208767516, 1.3471074380165289, 1.366690621631333, 1.4053180021559468, 1.2944664031620554, 1.2141573841178583, 1.1694214876033058, 1.1117499101688826, 1.05300035932447, 0.9960474308300395, 0.9892202659001078, 1.0077254761049228, 1.0452748832195473, 0.9782608695652174, 0.851598993891484, 0.6507366151634927, 0.5328781890046712, 0.35375494071146246, 0.17732662594322673, 0.0851598993891484, -0.0012576356449874237, -0.027847646424721522, 0.049586776859504134, 0.08677685950413223, -0.09809558030901905, -0.351598993891484, -0.6063600431189364, -0.8981315127560187, -1.0558749550844413, -1.0810276679841897, -1.1259432267337406, -1.2121810995328781, -1.2984189723320159, -1.3537549407114624, -1.400287459575997, -1.449694574200503, -1.5720445562342795, -1.6072583542939274, -1.557491915199425, -1.3494430470715055, -1.1358246496586417, -0.7896155228171039, -0.45670140136543297, -0.1331297161336687, 0.09611929572403881, 0.30686309737693135, 0.3778296802012217, 0.3868127919511319, 0.3731584620912684, 0.3395616241466044, 0.2964426877470356, 0.190801293568092, 0.10959396334890406, -0.002874595759971254, -0.11049227452389508, -0.1701401365432986, -0.23517786561264822, -0.27236794825727634, -0.2772188286022278, -0.22511678045274883, -0.15181458857348185, -0.07653611210923464, -0.08965145526410348, -0.17175709665828243, -0.28961552281710384, -0.37387711103126126, -0.5019762845849802, -0.6573841178584262, -0.6683435141933166, -0.7594322673374057, -0.5258713618397413, -0.3165648580668344, -0.4205892921307941, -0.625404240028746, -0.8584261588214157, -1.084800574919152, -1.2660797700323392, -1.3201581027667983, -1.390406036651096, -1.4753862738052461, -1.5438375853395616, -1.5901904419690982, -1.6306144448436939, -1.6861300754581388, -1.8203377650017967, -1.8573481854114264, -1.8460294646065396, -1.7466762486525333, -1.5941430111390587, -1.3956162414660438, -1.1757096658282429, -0.888789076536112, -0.6543298598634567, -0.4367588932806324, -0.2912324829320877, -0.1582824290334172, -0.11857707509881422, -0.062163133309378366, -0.02281710384477183, -0.04419690980955803, -0.09863456701401366, -0.21972691340280273, -0.34710743801652894, -0.41088753144089113, -0.4468199784405318, -0.4879626302551204, -0.49299317283507005, -0.4827524254401725, -0.45508444125044917, -0.4313690262306863, -0.445203018325548, -0.4629895795903701, -0.47197269134028025, -0.4588573481854114, -0.45957599712540426, -0.521200143729788, -0.4773625583902264, -0.4462809917355372, -0.29877829680201223, -0.12037369744879627, -0.24613726194753863, -0.5641394178943586, -0.8950772547610493, -1.1586417535034135, -1.2790154509522098, -1.3196191160618038, -1.316205533596838, -1.3587854832914121, -1.4157384117858427, -1.4090909090909092, -1.4306503772906936, -1.4651455264103486, -1.5170679123248294, -1.4545454545454546, -1.308480057491915, -0.8480057491915199, -0.36076176787639236, 0.2729069349622709, 0.7200862378727991, 1.0600071864893998, 1.259611929572404, 1.4243621990657565, 1.5052102048149478, 1.5215594681997844, 1.57599712540424, 1.6345670140136543, 1.6457060725835428, 1.6316924182536832, 1.5612648221343874, 1.4870643190801294, 1.4759252605102406, 1.4552641034854474, 1.427596119295724, 1.3792669780812072, 1.4349622709306504, 1.4414301113905856, 1.4313690262306864, 1.3616600790513833, 1.1629536471433706, 0.9766439094502336, 0.8383039885016169, 0.6757096658282429, 0.563600431189364, 0.41088753144089113, 0.3952569169960474, 0.391304347826087, 0.5120373697448797, 0.5001796622349982, 0.351598993891484, -0.0030542579949694574, -0.3731584620912684, -0.6943945382680561, -0.7942867409270571, -0.8406395975565936, -0.8762127200862379, -0.9256198347107438, -0.9755659360402443, -1.02299676607977, -1.0384477182896155, -1.0790513833992095, -1.1532518864534675, -1.1259432267337406, -1.0102407473948976, -0.6097736255839022, -0.18846568451311535, 0.3830398850161696, 0.8458498023715415, 1.1410348544735895, 1.2806324110671936, 1.4031620553359683, 1.4554437657204455, 1.4845490477901546, 1.5431189363995688, 1.5937836866690622, 1.6241466043837585, 1.64301113905857, 1.5474308300395256, 1.5043118936399569, 1.4473589651455263, 1.4473589651455263, 1.4216672655407834, 1.408192597915918, 1.438196191160618, 1.5048508803449514, 1.5535393460294646, 1.4543657923104563, 1.273805246137262, 1.0869565217391304, 0.9198706431908013, 0.7385914480776141, 0.6018684872439813, 0.3787279913762127, 0.32177506288178226, 0.24685591088753145, 0.37351778656126483, 0.47017606899029823, 0.24667624865253324, -0.12001437297879985, -0.48742364355012574, -0.7741645706072584, -0.871900826446281, -0.9342436219906576, -0.9414301113905857, -1.0228171038447718, -1.0840819259791592, -1.1218109953287818, -1.1173194394538268, -1.1309737693136903, -1.18199784405318, -1.1902623068630973, -1.067912324829321, -0.6963708228530363, -0.24092705713259072, 0.3566295364714337, 0.7930291052820697, 1.0637800934243622, 1.1498383039885016, 1.325188645346748, 1.401904419690981, 1.3999281351060007, 1.4004671218109954, 1.4247215235357529, 1.4457420050305425, 1.4277757815307222, 1.3751347466762487, 1.3111749910168882, 1.288896873877111, 1.2590729428674092, 1.2109234638878907, 1.194394538268056, 1.2513474667624864, 1.339381961911606, 1.369205892921308, 1.305605461731944, 1.1270212001437299, 0.9173553719008265, 0.7378727991376213, 0.5876751706791232, 0.447897951850521, 0.29572403880704273, 0.23176428314768235, 0.2400287459575997, 0.32267337405677327, 0.29590370104204095, 0.1117499101688825, -0.18954365792310457, -0.5409629895795903, -0.8639956881063601, -0.9865253323751347, -1.0346748113546533, -1.0434782608695652, -1.092705713259073, -1.1667265540783327, -1.1843334531081566, -1.1929572403880704, -1.2321236076176787, -1.2826086956521738, -1.2635644987423644, -1.1600790513833992, -0.763205174272368, -0.30255120373697447, 0.2883578871721164, 0.7035573122529645, 0.9913762127200862, 1.0959396334890406, 1.246496586417535, 1.2982393100970175, 1.3057851239669422, 1.3512396694214877, 1.3823212360761767, 1.4252605102407474, 1.4376572044556235, 1.362199065756378, 1.3176428314768236, 1.2984189723320159, 1.2878189004671219, 1.2588932806324111, 1.2096658282429034, 1.257096658282429, 1.3564498742364355, 1.3961552281710385, 1.304886812791951, 1.1800215594681998, 1.0025152712899748, 0.8413582464965864, 0.7130794107078692, 0.5440172475745598, 0.47646424721523534, 0.36902623068630974, 0.42777578153072227, 0.40837226015091627, 0.36399568810636, 0.10959396334890406, -0.23499820337765, -0.5677326625943226, -0.8621990657563781, -1.012396694214876, -1.0294646065397053, -1.027488321954725, -1.077793747754222, -1.1415738411785843, -1.1911606180380885, -1.1906216313330937, -1.2312252964426877, -1.296802012217032, -1.2626661875673733, -1.1494789795185052, -0.7800934243621991, -0.30524613726194755, 0.28781890046712183, 0.7231404958677686, 1.0066475026949335, 1.1031261228889688, 1.2490118577075098, 1.3041681638519582, 1.3135106000718648, 1.3420768954365792, 1.3607617678763924, 1.4053180021559468, 1.3956162414660438, 1.31099532878189, 1.1922385914480775, 1.1437297879985626, 1.0941430111390587, 1.0154509522098454, 0.9453826805605462, 0.9464606539705354, 0.9805964786201941, 1.0292849443047072, 0.9906575637800934, 0.8436938555515631, 0.7055335968379447, 0.5761767876392382, 0.4464606539705354, 0.2547610492274524, 0.14444843693855552, 0.07815307222421847, 0.08803449514911965, 0.11354653251886454, 0.0795903701042041, -0.13007545813869925, -0.42382321236076176, -0.7051742723679483, -1.0021559468199785, -1.1203736974487963, -1.1658282429033417, -1.1859504132231404, -1.2757815307222422, -1.3332734459216673, -1.3983111749910169, -1.418792669780812, -1.4791591807402085, -1.6015091627739848, -1.644807761408552, -1.6007905138339922, -1.3900467121810995, -1.1841537908731585, -0.8913043478260869, -0.5767157743442328, -0.2545813869924542, -0.024793388429752067, 0.1859504132231405, 0.27991376212720087, 0.3149478979518505, 0.33776500179662233, 0.32680560546173193, 0.31620553359683795, 0.2184692777578153, 0.11444484369385555, -0.008264462809917356, -0.14193316564858066, -0.17642831476823573, -0.2175709665828243, -0.2660797700323392, -0.27883578871721165, -0.24344232842256558, -0.12073302191879266, -0.06521739130434782, -0.047071505569529284, -0.09450233560905498, -0.1649299317283507, -0.25134746676248654, -0.3127919511318721, -0.4035213798059648, -0.4782608695652174, -0.5086237872799138, -0.39112468559108876, -0.3850161696011498, -0.5334171757096658, -0.7355371900826446, -0.9545454545454546, -1.2042759611929572, -1.3514193316564858, -1.386094143011139, -1.3780093424362199, -1.4554437657204455, -1.534315486884657, -1.5979159180740208, -1.637800934243622, -1.6857707509881423, -1.8014732303269854, -1.8726194753862737, -1.8402802730865973, -1.7346388789076537, -1.6288178224937118, -1.447897951850521, -1.2513474667624864, -1.041501976284585, -0.8273445921667265, -0.5970176068990298, -0.4033417175709666, -0.24056773266259432, -0.11857707509881422, -0.03233920229967661, 0.022637441609773625, 0.0745598275242544, 0.03251886453467481, -0.13672296083363278, -0.2675170679123248, -0.3620194035213798, -0.39543657923104564, -0.4369385555156306, -0.47071505569529287, -0.4405318002155947, -0.3704635285662954, -0.3395616241466044, -0.31081566654689186, -0.3259072942867409, -0.3521379805964786, -0.3356090549766439, -0.36363636363636365, ...]
3. Filter the values in electricity_demand
that are greater than the mean¶
In [18]:
[sample for sample in electricity_demand if sample > 29617]
Out[18]:
[31020, 33529, 35428, 36034, 36834, 37296, 37338, 37608, 37692, 37944, 37880, 37493, 37065, 36855, 36871, 36837, 36603, 36982, 37369, 37650, 37413, 36475, 35486, 34452, 33704, 32883, 31940, 32215, 32572, 32850, 32251, 30895, 32023, 34315, 35927, 36367, 37087, 37184, 37009, 37212, 37531, 37890, 37982, 37540, 37160, 36920, 37060, 36930, 36640, 36910, 37220, 37530, 37320, 36331, 35206, 34203, 33273, 32376, 31838, 31211, 31505, 31838, 32185, 30881, 32034, 34235, 35694, 35978, 36475, 36675, 36720, 36842, 36890, 36917, 36854, 36525, 36431, 36212, 36061, 35931, 35835, 36148, 36523, 36859, 36731, 35804, 34721, 34035, 33234, 32532, 31474, 31957, 32500, 32586, 31917, 30636, 31876, 34363, 35819, 36295, 36949, 37095, 37086, 37520, 37540, 37671, 37695, 37314, 37113, 36796, 36705, 36634, 36357, 36664, 37020, 37152, 36836, 36008, 34981, 34265, 33385, 32477, 31966, 31402, 31703, 32192, 32322, 30972, 31838, 34308, 36305, 36743, 37705, 37980, 38084, 38379, 38526, 38429, 38344, 37785, 37495, 37190, 37010, 36641, 36296, 36309, 36532, 36662, 36229, 35321, 34409, 33425, 32708, 31460, 30955, 30274, 30302, 30427, 30154, 29915, 30895, 31273, 31390, 31287, 31163, 30811, 30310, 29767, 29721, 30973, 33497, 35192, 35624, 36444, 36903, 36944, 37223, 37345, 37710, 37641, 37391, 37116, 37017, 37024, 36882, 36605, 36861, 37241, 37550, 37215, 36203, 35035, 34112, 33482, 32349, 31186, 30920, 30270, 31869, 31651, 30821, 31600, 34011, 35567, 35946, 36733, 36963, 37009, 37100, 37265, 37478, 37462, 37040, 36778, 36679, 36570, 36509, 36433, 36730, 37125, 37359, 36995, 36149, 34845, 33986, 33353, 32595, 31833, 31382, 31264, 31805, 32067, 30723, 32093, 34598, 36118, 36505, 37295, 37562, 37546, 37734, 38071, 38204, 38233, 37710, 37459, 37224, 37208, 36962, 36837, 37151, 37602, 38055, 37780, 36832, 35861, 35202, 34347, 33562, 32860, 32606, 32578, 32552, 32256, 30893, 32017, 34569, 36166, 36510, 37250, 37372, 37318, 37333, 37611, 37736, 37756, 37275, 37010, 36926, 36837, 36726, 36449, 36734, 37067, 37174, 36824, 35980, 34953, 34235, 33350, 32664, 31923, 31603, 31736, 32134, 31993, 30956, 31647, 34117, 35590, 36167, 36741, 36768, 36783, 36991, 37115, 37224, 37439, 36822, 36375, 36126, 35805, 35478, 35161, 35123, 35226, 35435, 35062, 34357, 33239, 32583, 31586, 30604, 30091, 29893, 30100, 30152, 31325, 31720, 31770, 31694, 31507, 31267, 30679, 30227, 31136, 33625, 35517, 36628, 37545, 37995, 38086, 38389, 38715, 38777, 38699, 38307, 37894, 37832, 37717, 37563, 37294, 37604, 37640, 37584, 37196, 36090, 35053, 34283, 33378, 32754, 31904, 31817, 31795, 32467, 32401, 31574, 31749, 34325, 35968, 36745, 37427, 37718, 37880, 38206, 38488, 38657, 38762, 38230, 37990, 37673, 37673, 37530, 37455, 37622, 37993, 38264, 37712, 36707, 35667, 34737, 33728, 32967, 31725, 31408, 30991, 31696, 32234, 30990, 31602, 34031, 35538, 36017, 36993, 37420, 37409, 37412, 37547, 37664, 37564, 37271, 36915, 36791, 36625, 36357, 36265, 36582, 37072, 37238, 36884, 35890, 34723, 33724, 32888, 32110, 31263, 30907, 30953, 31413, 31264, 30239, 31222, 33533, 35135, 35717, 36555, 36843, 36885, 37138, 37311, 37550, 37619, 37199, 36951, 36844, 36785, 36624, 36350, 36614, 37167, 37388, 36880, 36185, 35197, 34300, 33586, 32645, 32269, 31671, 31998, 31890, 31643, 30227, 31219, 33642, 35220, 35757, 36569, 36876, 36928, 37087, 37191, 37439, 37385, 36914, 36253, 35983, 35707, 35269, 34879, 34885, 35075, 35346, 35131, 34313, 33544, 32824, 32102, 31035, 30421, 30052, 30107, 30249, 30060, 30652, 31175, 31370, 31497, 31436, 31377, 30833, 30254, 29743, 30032, 29798, 30507, 33060, 34783, 35322, 36130, 36494, 36593, 36826, 36985, 37098, 37200, 36654, 36464, 36257, 36157, 36098, 35959, 36207, 36559, 36790, 36577, 35727, 34602, 33578, 32714, 31926, 31142, 30833, 31109, 31310, 31236, 30184, 31278, 33530, 35240, 35783, 36372, 36610, 36651, 36835, 37248, 37128, 37230, 36841, 36529, 36500, 36445, 36348, 36152, 36282, 36853, 37137, 36844, 35875, 34589, 33987, 32959, 32015, 31847, 31404, 31501, 31824, 31759, 30395, 31383, 33907, 35592, 36022, 36643, 36976, 36985, 37123, 37144, 37385, 37334, 36914, 36630, 36433, 36461, 36246, 36131, 36534, 37099, 37346, 37098, 36145, 34997, 34342, 33431, 33088, 32201, 32185, 31966, 32214, 31736, 30325, 31494, 33985, 35754, 35972, 36855, 37135, 37159, 37282, 37347, 37408, 37444, 37066, 36874, 36696, 36707, 36456, 36362, 36506, 36831, 37268, 36851, 36027, 34950, 34149, 33515, 32938, 32777, 32443, 32620, 32453, 31486, 30006, 31283, 33772, 35443, 35929, 36898, 37272, 37270, 37363, 37445, 37550, 37543, 36995, 36620, 36032, 35843, 35606, 35131, 35079, 35341, 35546, 35305, 34459, 33526, 32835, 32000, 31136, 30696, 30054, 29993, 30178, 29786, 29687, 30737, 31531, 31785, 31805, 31710, 31593, 31228, 30907, 30011, 29983, 30335, 30650, 30474, 29654, 30833, 33448, 35245, 35900, 36798, 37251, 37335, 37677, 37887, 38066, 38091, 37784, 37622, 37408, 37354, 37172, 36995, 37311, 37693, 37887, 37446, 36451, 35267, 34434, 33733, 32812, 32061, 32089, 32345, 32564, 32096, 30702, 31617, 34140, 35901, 36473, 37122, 37559, 37703, 37933, 38059, 38274, 38303, 37876, 37688, 37414, 37312, 37234, 37086, 37421, 37923, 38363, 38127, 37433, 36363, 35617, 34829, 34036, 33520, 33163, 33322, 32823, 32221, 30611, 31571, 33923, 35446, 35973, 36833, 37164, 37342, 37642, 37713, 37898, 37963, 37603, 37290, 36955, 36956, 36815, 36637, 37003, 37526, 37775, 37630, 36722, 35559, 34742, 34002, 33230, 32809, 32446, 32614, 32715, 32150, 30568, 31552, 34093, 35828, 36337, 37142, 37407, 37471, 37632, 37920, 38095, 38118, 37735, 37411, 37205, 37064, 36870, 36749, 37029, 37542, 37684, 37470, 36532, 35290, 34597, 33819, 33104, 32718, 32512, 32693, 32784, 32151, 30654, 31460, 33905, 35501, 36128, 36898, 37056, 37165, 37294, 37516, 37537, 37478, 36905, 36316, 36081, 35478, 35101, 34944, 34929, 35327, 35498, 35065, 34315, 33258, 32375, 31716, 30629, 29779, 29776, 29963, 30662, 31096, 31292, 31464, 31393, 31269, 30742, 30282, 30153, 30634, 31033, 30704, 29870, 30787, 33457, 35273, 36011, 36866, 37346, 37510, 37825, 38248, 38518, 38621, 38270, 37907, 37766, 37646, 37477, 37261, 37766, 38302, 38496, 38279, 37451, 36435, 35601, 34543, 33925, 33161, 32709, 32881, 32719, 32030, 30569, 31634, 34080, 35646, 36079, 36758, 36958, 37169, 37410, 37601, 37773, 37672, 37245, 36995, 36519, 36533, 36464, 36274, 36577, 37042, 37242, 36996, 36020, 34759, 33932, 33001, 32254, 31581, 31270, 31776, 32287, 32117, 30604, 31689, 33984, 35449, 35832, 36526, 36882, 36959, 37105, 37355, 37510, 37519, 37159, 36810, 36474, 36565, 36459, 36267, 36585, 37062, 37301, 37110, 36312, 35274, 34483, 33804, 33187, 32918, 32800, 32820, 32686, 31877, 30754, 32005, 34393, 35901, 36370, 37303, 37585, 37565, 37943, 37990, 38062, 38124, 37692, 37429, 37067, 37005, 36949, 36646, 37019, 37402, 37476, 37062, 36292, 35247, 34449, 33822, 32999, 32569, 32485, 32879, 32866, 32106, 30590, 31541, 33932, 35554, 36040, 36630, 36857, 36971, 37020, 37181, 37304, 37487, 36880, 36159, 35654, 35564, 35302, 34901, 34910, 35229, 35529, 35253, 34636, 33774, ...]
4. Filter only companies that end with an X
¶
In [22]:
[comp for comp in sp_companies if comp.endswith('X')]
Out[22]:
['BAX', 'BDX', 'BSX', 'CLX', 'CSX', 'CVX', 'DGX', 'EFX', 'EIX', 'EQIX', 'ESRX', 'FCX', 'FDX', 'FOX', 'HOLX', 'IDXX', 'KMX', 'LRCX', 'NFLX', 'NFX', 'PAYX', 'PSX', 'PX', 'SBUX', 'STX', 'TJX', 'TWX', 'UTX', 'VRTX', 'XLNX', 'XRX']
5. Return the length of the ticker for companies that end with an L
¶
In [23]:
[len(comp) for comp in sp_companies if comp.endswith('L')]
Out[23]:
[3, 4, 3, 3, 3, 3, 2, 3, 3, 3, 3, 2, 2, 5, 3, 3, 1, 3, 3, 3, 3, 4, 3, 4, 3, 2, 4, 3, 3, 3, 2, 3]
6. Return the ticker and its length (in characters) for companies that contain an X
in its ticker¶
In [25]:
[(ticker, len(ticker)) for ticker in sp_companies if 'X' in ticker]
Out[25]:
[('ALXN', 4), ('AXP', 3), ('BAX', 3), ('BDX', 3), ('BSX', 3), ('BXP', 3), ('CLX', 3), ('CSX', 3), ('CTXS', 4), ('CVX', 3), ('CXO', 3), ('DGX', 3), ('DXC', 3), ('EFX', 3), ('EIX', 3), ('EQIX', 4), ('ESRX', 4), ('EXC', 3), ('EXPD', 4), ('EXPE', 4), ('EXR', 3), ('FCX', 3), ('FDX', 3), ('FOX', 3), ('FOXA', 4), ('HOLX', 4), ('IDXX', 4), ('KMX', 3), ('LRCX', 4), ('NFLX', 4), ('NFX', 3), ('OXY', 3), ('PAYX', 4), ('PSX', 3), ('PX', 2), ('PXD', 3), ('SBUX', 4), ('STX', 3), ('TJX', 3), ('TWX', 3), ('TXN', 3), ('TXT', 3), ('UTX', 3), ('VRTX', 4), ('XEC', 3), ('XEL', 3), ('XL', 2), ('XLNX', 4), ('XOM', 3), ('XRAY', 4), ('XRX', 3), ('XYL', 3)]
7. Format the result from the previous activity to return a single string with the ticker and its length¶
In [ ]:
8. What's the mean of the prices in sp_prices
?¶
In [30]:
np.mean([price for ticker, price in sp_prices])
Out[30]:
107.76220792079208
9. Return ticker and stock price of companies in sp_prices
whose price is above the mean¶
In [33]:
[(ticker, price) for ticker, price in sp_prices if price > 107]
Out[33]:
[('AAP', 109.93), ('AAPL', 159.54), ('ABBV', 113.62), ('ACN', 155.15), ('ADBE', 192.34), ('ADP', 113.56), ('ADS', 246.75), ('ADSK', 110.54), ('AET', 181.49), ('AGN', 170.39), ('ALGN', 234.33), ('ALXN', 117.15), ('AMG', 187.87), ('AMGN', 177.47), ('AMP', 160.11), ('AMT', 140.0), ('AMZN', 1416.78), ('ANSS', 155.03), ('ANTM', 238.44), ('AON', 140.55), ('APD', 158.21), ('ARE', 118.96), ('AVB', 158.28), ('AVGO', 237.38), ('AVY', 114.78), ('AYI', 148.07), ('AZO', 728.33), ('BA', 348.12), ('BDX', 221.92), ('BIIB', 326.89), ('BLK', 532.26), ('BRK.B', 200.37), ('BXP', 115.34), ('CAT', 154.34), ('CB', 147.52), ('CBOE', 114.565), ('CCI', 108.75), ('CHTR', 363.55), ('CI', 195.44), ('CLX', 127.82), ('CME', 159.93), ('CMG', 272.21), ('CMI', 172.74), ('COL', 135.4), ('COO', 230.47), ('COST', 183.19), ('CRM', 110.05), ('CTAS', 156.6), ('CVX', 115.29), ('CXO', 148.1), ('DE', 161.44), ('DPS', 118.0), ('EA', 123.05), ('ECL', 133.12), ('EFX', 117.6), ('EL', 134.71), ('EQIX', 426.08), ('ESS', 217.81), ('EW', 129.7), ('EXPE', 129.33), ('FB', 180.18), ('FDX', 251.15), ('FFIV', 141.39), ('FISV', 129.17), ('FRT', 111.34), ('GD', 214.95), ('GOOG', 1048.58), ('GOOGL', 1055.41), ('GS', 257.1), ('GWW', 259.89), ('HD', 191.29), ('HII', 234.82), ('HON', 151.19), ('HRS', 152.79), ('HUM', 264.9), ('IBM', 153.85), ('IDXX', 176.83), ('IFF', 142.7), ('ILMN', 221.2), ('INTU', 161.29), ('ISRG', 399.53), ('IT', 119.45), ('ITW', 163.44), ('JBHT', 117.95), ('JNJ', 131.42), ('JPM', 112.87), ('KMB', 112.36), ('KSU', 107.1), ('LH', 169.66), ('LLL', 207.69), ('LMT', 345.43), ('LRCX', 171.63), ('LYB', 110.27), ('MA', 168.73), ('MAR', 139.64), ('MCD', 165.71), ('MCK', 152.83), ('MCO', 157.98), ('MHK', 267.66), ('MLM', 218.85), ('MMM', 233.19), ('MON', 120.41), ('MTB', 184.97), ('MTD', 641.96), ('NEE', 148.09), ('NFLX', 264.56), ('NOC', 337.66), ('NSC', 142.68), ('NVDA', 228.8), ('ORLY', 252.08), ('PCLN', 1882.68), ('PEP', 113.5), ('PH', 183.31), ('PKG', 117.13), ('PNC', 155.0), ('PPG', 114.13), ('PRU', 111.17), ('PSA', 185.35), ('PVH', 149.21), ('PX', 150.01), ('PXD', 176.2), ('RCL', 128.52), ('RE', 246.7), ('REGN', 334.61), ('RHT', 128.81), ('RL', 107.7), ('ROK', 188.78), ('ROP', 266.19), ('RTN', 204.32), ('SBAC', 166.51), ('SHW', 403.48), ('SJM', 119.83), ('SNA', 166.63), ('SPG', 154.86), ('SPGI', 182.69), ('STZ', 214.15), ('SWK', 159.74), ('SYK', 153.67), ('TDG', 292.1), ('TMO', 207.55), ('TRV', 142.14), ('UHS', 117.12), ('ULTA', 218.06), ('UNH', 225.82), ('UNP', 128.96), ('UPS', 111.91), ('URI', 173.58), ('UTX', 131.97), ('V', 119.65), ('VAR', 116.92), ('VMC', 128.24), ('VRSN', 109.11), ('VRTX', 155.67), ('WAT', 201.98), ('WHR', 171.52), ('WLTW', 157.38), ('WYN', 118.72), ('WYNN', 177.32), ('ZBH', 120.78)]
10. Return the price of the stocks of the FAANG companies¶
In [34]:
faang_tickers = ['FB', 'AMZN', 'AAPL', 'NFLX', 'GOOGL']
In [37]:
[price for ticker, price in sp_prices if ticker in faang_tickers]
Out[37]:
[159.54, 1416.78, 180.18, 1055.41, 264.56]
11. Return the price and the ticker of those copanies that start with a B
and contain an X
(anywhere in the ticker)¶
In [ ]: