menu
Tutorials

Exporting to Excel

Risk in GS Quant is returned as Pandas Dataframes. These can easily be written to Excel, for use in presentations etc. Note that you will need XlsxWriter installed for this to work.

Get Dataframe

import datetime
from gs_quant.data import Dataset

weather_ds = Dataset(Dataset.GS.WEATHER)
panda_df = weather_ds.get_data(datetime.date(2016, 1, 15), datetime.date(2016, 1, 16), city=['Boston', 'Austin'])

Output:

Out[1]:
     city        date    ...                    updateTime  windSpeed
0  Boston  2016-01-15    ...      2017-03-06T16:49:36.472Z        5.2
1  Boston  2016-01-16    ...      2017-03-06T16:49:36.472Z        6.9
2  Austin  2016-01-15    ...      2017-03-06T16:49:36.524Z        0.0
3  Austin  2016-01-16    ...      2017-03-06T16:49:36.524Z        0.0
[4 rows x 10 columns]

Constructing an Excel Worksheet

writer = pd.ExcelWriter(r'C:\Temp\Weather.xlsx', engine='xlsxwriter')       # Create workbook
panda_df.to_excel(writer, sheet_name='Weather')                             # Create a sheet called Weather


for measure, values in panda_df.items():
    pd.DataFrame({measure: values}).to_excel(writer, sheet_name=measure)    # Write values to the sheet

writer.save()

Now you can open the workbook directly in Excel


Related Content