You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think I understand how to properly pull weekly data with yfinance. I seem to get different dates in return depending on the start and end date I select. In reality, I just want M-F data in a single pandas dataframe row. Sometimes the data I get back has dates listed as Mondays, sometimes Wednesdays, etc. How can I just get a Monday-Friday trading week in return?
Further, it seems the data can be incomplete. For example, if I want to compare weekly data between two tickers for the same time period, the end result should (in theory) contain the same number of weekly data points. In reality, I get two different results. Here is an example:
# Get the first dataframe
df1 = pdr.get_data_yahoo('GDX', '2014-12-29', '2020-11-29', interval='1wk')
df1 = df1.reset_index().drop_duplicates(subset='Date', keep='last').set_index('Date')
df1 = df1.dropna(how='all')
# Get the second dataframe
df2 = pdr.get_data_yahoo('QQQ', '2014-12-29', '2020-11-29', interval='1wk')
df2 = df2.reset_index().drop_duplicates(subset='Date', keep='last').set_index('Date')
df2 = df2.dropna(how='all')
# Compare the results. Since the start and end dates are the same between the two calls, they should have the same shape.
print(df1.shape) # This equals (306, 6)
print(df2.shape) # This equals (298, 6)
Clearly, there are missing entries in df2 that exist in df1. How can I get the two dataframes to contain the same number of entries, with the exact same dates and row indices?
Because depending on the index, some of them may be monthly reports, other weekly or "business-daily". They do not come from some standard vendor so they do not have to line up.
Sometimes the data I get back has dates listed as Mondays, sometimes Wednesdays, etc.
This is still an issue but caused by Yahoo. Solution is to shift start date back a few days to e.g. Saturday. Stupid but works. One day yfinance will do weekly properly (there are other problems in Yahoo)
I don't think I understand how to properly pull weekly data with yfinance. I seem to get different dates in return depending on the start and end date I select. In reality, I just want M-F data in a single pandas dataframe row. Sometimes the data I get back has dates listed as Mondays, sometimes Wednesdays, etc. How can I just get a Monday-Friday trading week in return?
Further, it seems the data can be incomplete. For example, if I want to compare weekly data between two tickers for the same time period, the end result should (in theory) contain the same number of weekly data points. In reality, I get two different results. Here is an example:
Clearly, there are missing entries in df2 that exist in df1. How can I get the two dataframes to contain the same number of entries, with the exact same dates and row indices?
I can examine the differences, like:
The text was updated successfully, but these errors were encountered: