项目作者: pmbaumgartner

项目描述 :
IPython Magic for exporting pandas objects to Excel
高级语言: Python
项目地址: git://github.com/pmbaumgartner/excelify.git
创建时间: 2018-02-01T22:45:35Z
项目社区:https://github.com/pmbaumgartner/excelify

开源协议:MIT License

下载


Excelify

Easily export pandas objects to Excel spreadsheets with IPython magic.

Build Status codecov

Install

pip install excelify

or

pip install https://github.com/pmbaumgartner/excelify/releases/download/v0.4/excelify-0.4.tar.gz

then:

%load_ext excelify

Example

%excel

  1. %load_ext excelify
  2. data = [
  3. {'name' : 'Greg', 'age' : 30},
  4. {'name' : 'Alice', 'age' : 36}
  5. ]
  6. df = pd.DataFrame(data)
  7. %excel df -f spreadsheet.xlsx -s sample_data

Magics

%excel

  1. %excel [-f FILEPATH] [-s SHEETNAME] dataframe
  2. Saves a DataFrame or Series to Excel
  3. positional arguments:
  4. dataframe DataFrame or Series to Save
  5. optional arguments:
  6. -f FILEPATH, --filepath FILEPATH
  7. Filepath to Excel spreadsheet.Default:
  8. './{object}_{timestamp}.xlsx'
  9. -s SHEETNAME, --sheetname SHEETNAME
  10. Sheet name to output data.Default:
  11. {object}_{timestamp}

%excel_all

  1. %excel_all [-f FILEPATH] [-n NOSORT]
  2. Saves all Series or DataFrame objects in the namespace to Excel.
  3. Use at your own peril. Will not allow more than 100 objects.
  4. optional arguments:
  5. -f FILEPATH, --filepath FILEPATH
  6. Filepath to excel spreadsheet.Default:
  7. './all_data_{timestamp}.xlsx'
  8. -n NOSORT, --nosort NOSORT
  9. Turns off alphabetical sorting of objects for export
  10. to sheets

Dependencies

  • IPython
  • Pandas
  • XlsxWriter

    Why?

I had several Jupyter notebooks that were outputting crosstabs or summary statistics that would eventually end up in a Word doc. Depending on the size and complexity of the table, I would either copy/paste or export to Excel. Due to the inconsistency, this made managing all these tables a pain. I figured a tool like this would make it easier to collect everything in a notebook as part of an analysis into one excel file, deal with formatting in excel, and review and insert into a doc from there.