1: Scrape the wikipedia page to get the S&P 500 stocks. use a…
Question Answered step-by-step 1: Scrape the wikipedia page to get the S&P 500 stocks. use a… 1: Scrape the wikipedia page to get the S&P 500 stocks. use a function get_SP500_wikipedia_data() that reads List of S&P 500 companies and returns a DataFrame with these columns, sorted by ‘Symbol’:’Symbol”Security”GICS Sector”Headquarters Location’Hints:To retrieve the tables on that page, use pd.read_html().(https://en.wikipedia.org/wiki/List_of_S%26P_500_companies) Then select the required table and columns.To sort by ‘Symbol’, use df.sort_values(by=’Symbol’, ignore_index=True). ? Here is some test code for the function:In [2]: 1df = get_SP500_wikipedia_data()2DPZ = df[df[‘Symbol’] == ‘DPZ’]3assert DPZ[‘Security’].iloc[0] == “Domino’s”4assert DPZ[‘GICS Sector’].iloc[0] == ‘Consumer Discretionary’5assert DPZ[‘Headquarters Location’].iloc[0] == ‘Ann Arbor, Michigan’ Computer Science Engineering & Technology Python Programming Share QuestionEmailCopy link Comments (0)


