import datetime
import pandas.io.data
sp = pd.io.data.get_data_yahoo('^IXIC',start = datetime.datetime(1972, 1, 3),
end = datetime.datetime(2010, 1, 3))
I have used the above example, but that just pulls DAILY data into a dataframe when I would like to pull weekly. It doesn't seem like get_data_yahoo
has a parameter where you can select perhaps from daily, weekly or monthly like the options made available on yahoo itself. Any other packages or ideas that you know of that might be able to facilitate this?
Save historical data from a desktop browser Click Historical Data. Select a Time Period, data to Show, and Frequency. Click Apply. To use the data offline, click Download.
Yahoo! Finance provides the simplest way to import financial data into a spreadsheet. The data (including stock prices, indices and company fundamentals) can be automatically downloaded in a CSV by simply entering a URL into your browser's address bar. The CSV can then be opened in Excel and manipulated as required.
You can downsample using the asfreq
method:
sp = sp.asfreq('W-FRI', method='pad')
The pad
method will propagate the last valid observation forward.
Using resample
(as @tshauck has shown) is another possibility.
Use asfreq
if you want to guarantee that the values in your downsample are values found in the original data set. Use resample
if you wish to aggregate groups of rows from the original data set (for example, by taking a mean). reindex
might introduce NaN values if the original data set does not have a value on the date specified by the reindex -- though (as @behzad.nouri points out) you could use method=pad
to propagate last observations here as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With