0
votes

#Hello i have 2 dataframes as per below

!pip install yahoo_earnings_calendar

import pandas as pd`enter code here`
from datetime import datetime
from datetime import timedelta
from yahoo_earnings_calendar import YahooEarningsCalendar
import dateutil.parser

#setting the report date

report_date = datetime.now().date()

#downloading the earnings calendar

yec = YahooEarningsCalendar()
earnings_list = yec.earnings_on(report_date)

#saving the data in a pandas DataFrame

 earnings_df = pd.DataFrame(earnings_list)

Printing out earnings_df will give me daily stock earnings under Yahoo.

However if i only want the stock tickers for SNP for example,how do i extract only those tickers that fall under S&P , dow jones or nasdaq ?

The below code provides me with ah list of snp stock tickers.

table=pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
snp = table[0]
snp= snp['Symbol']
print(snp)

How do i compare the 'Symbol' column in snp from 'ticker' column in earnings_list and only sift out the symbols in snp from the earning_list ?

thanks.

1
Have you seen pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html? This should have all the ansers you need. In your case something similar to earnings_df[earnings_df['Ticker'].isin(snp)] should do the job.maow

1 Answers

0
votes

Tried using this below code,

>>> tickers_in_snp=earnings_df[earnings_df['ticker'].isin(snp)]

This gives a dataframe of values where values of tickers present in symbol column of snp.

>>> tickers_in_snp.head()
    companyshortname  epsactual  ...  startdatetimetype  ticker
8     Amazon.com Inc        NaN  ...                AMC    AMZN
9   A. O. Smith Corp        NaN  ...                BMO     AOS
15  Under Armour Inc        NaN  ...                TAS     UAA
19      Alphabet Inc        NaN  ...                AMC   GOOGL
26         Aptiv PLC        NaN  ...                BMO    APTV
[5 rows x 9 columns]

[64 rows x 9 columns] is shape of new data frame after filtering values that are available at snp.