Search code examples
pythonpandasdataframepandas.excelwriter

pandas won't write dataframe to excel file, it remains empty


My dataframe looks like this:

           exp    gamma%   proba-a%                spread-test in %
0    -6.415879     0.100  34.503457  0.1277374979529247122928732004
1    -4.558370     0.200  26.517913  0.1277374979529247122928732004
2    -2.821595     0.300  17.875550  0.1277374979529247122928732004
3    -2.118973     0.400  14.736015  0.1277374979529247122928732004
4    -1.665637     0.500  12.837838  0.1277374979529247122928732004
5    -1.326727     0.600  11.467630  0.1277374979529247122928732004
6    -1.048364     0.700  10.314268  0.1277374979529247122928732004
7    -0.819480     0.800   9.355751  0.1277374979529247122928732004
8    -0.623309     0.900   8.475801  0.1277374979529247122928732004
9    -0.466824     1.000   7.847266  0.1277374979529247122928732004

I would like to write it in an excel sheet. What I tried:

from pandas import ExcelWriter

writer = ExcelWriter('spread32.xlsx')
yourdf.to_excel(writer)
writer.save()

But nothing written in the excel file, it remains empty.

Is it because I am using jupyter notebook? The excel file already exists.


Solution

  • for completeness sake:
    when you save a file with a relative path, it will be in relative to where you are running from. its not always immediately clear where jupyter is running so either use a full path or do %pwd to check where you actually are