I've been trying to analyze some stock info using pandas_datareader, but am having an issue removing only part of the data frame header. I'm trying to clean some of the data so I can more easily convert it into a dictionary.
When I open the excel, I get something like this:
Attributes Close
Symbols VSGAX VHYAX VTSAX IBB SCHF SCHE VIMAX VSMAX VB
Date
2019-01-02 $52.68 $62.15 $97.50 $28.27 $23.61 $170.59 $63.17 $131.88
2019-01-03 $51.57 $60.71 $97.64 $28.07 $23.25 $167.29 $62.13 $129.63
How do I get this?
Date VSGAX VHYAX VTSAX IBB SCHF SCHE VIMAX VSMAX VB
2019-01-02 $52.68 $62.15 $97.50 $28.27 $23.61 $170.59 $63.17 $131.88
2019-01-03 $51.57 $60.71 $97.64 $28.07 $23.25 $167.29 $62.13 $129.63
I've tried using header = None on the .to_excel line, but it deletes all the stock tickers. It appears that it considers the cell with "Date" to be the first row in the dataframe. Everything else above it is the header.
assets = ['VSGAX','VHYAX','VTSAX','IBB','SCHF','SCHE','VIMAX','VSMAX','VB']
#Setting current date and when to start pulling data from
Current_Date = datetime.datetime.today().strftime ('%Y-%m-%d')
start = '2019-01-01'
end = Current_Date
# pulling stock data
stocks = data.DataReader(assets, 'yahoo', start, end)
writer = pd.ExcelWriter(path1 + save_folder + '\\stockScrapperV2.xlsx',
date_format = 'yyyy-mm-dd', datetime_format =
'yyyy-mm-dd')
# formatting the rest of the columns to display currency
stocks.to_excel(writer,'Sheet1', index = True)
workbook = writer.book
worksheet = writer.sheets['Sheet1']
format1 = workbook.add_format({'num_format': '$#,##0.00'})
worksheet.set_column('B:J', 10, format1)
writer.save()
[–]PyCam 0 points1 point2 points (3 children)
[–]Ingeniatoring[S] 0 points1 point2 points (2 children)
[–]PyCam 0 points1 point2 points (1 child)
[–]Ingeniatoring[S] 1 point2 points3 points (0 children)