Skip to main content

A package for writing nicely formatted Pandas dataframes in Excel data files

Project description

nicexcel is a lightweight Python package that provides the possibility of exporting pandas native DataFrame objects into nicely formatted MS Excel files.

The package leverages pandas and openpyxl open-source Python libraries to add some simple aesthetic details to output Excel files. This improves the overall aspect and usability of the files, hence, it can help in the automation of reporting activities.

  1. Column widths auto-adapted to fit characters contained inside them
  2. Header row containing filterable columns within Excel (by default)
  3. Header row freezed (by default)
  4. No indexing by default (vs pandas default index set on)
  5. Easy possibility of number formatting of columns, within dict arguments

Getting started with to_excel()

The nicexcel package main functionality consists in the exporting of pandas.DataFrame object. The to_excel() method is conceived as a wrapper of the popular pd.DataFrame.to_excel() that takes two key inputs:

  • df: pd.DataFrame instance
  • filename: string containing file path where the output .xlsx file will be saved

See below a simple example of application

import nicexcel as nl
import pandas as pd

# instantiate mock data
mock_df = pd.DataFrame({'Product Line': ["T-Shirts", "Jeans", "Jackets"], 
'Yearly Revenues': [30000.0411, 45513.1228, 10220.103],
'Gross Margin (%)': [0.223, 0.1151, 0.458]})

# column format
cols_format = {'Integer': ['Yearly Income'], '%': ['Gross Margin (%)']}

# generate nicely formatted excel
nl.to_excel(
    df=mock_df,
    filename='output.xlsx',
    cols_format=cols_format
    )

A second method: to_excel_ms()

In a similar fashion, the nicexcel.to_excel_ms() [^1] allows the possibility of exporting a group of different pd.DataFrame objects to the same output .xlsx files on different worksheets.

The method takes two main arguments

  • dfs: dict of pd.DataFrame instances
  • filename: string containing file path where the output .xlsx file will be saved

See a sample application below.

import nicexcel as nl

# get sample data
df1 = ...
df2 = ...

# initiate dataframe
dfs = {'  ': df1, ' ': df2}

# column format, fix this
cols_format = {'Integer': ['Yearly Income'], '%': ['Margin (%)']}

# generate nicely formatted excel
nl.to_excel_ms(
    dfs=dfs,
    filename='output.xlsx',
    cols_format=cols_format
    )

)

Documentation

The documentation is available in docstrings provided within the code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nicexcel-0.1.7.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nicexcel-0.1.7-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file nicexcel-0.1.7.tar.gz.

File metadata

  • Download URL: nicexcel-0.1.7.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for nicexcel-0.1.7.tar.gz
Algorithm Hash digest
SHA256 63d2793eea926b15df7ca625ad16f54fb6140963339fef4f9b85298300024dc6
MD5 048b4ba364d9dfe51d26f2675fa06663
BLAKE2b-256 9ad3db9f1e23f4b118a447668efb056f302a86781e71510762dcf5d5465b0319

See more details on using hashes here.

File details

Details for the file nicexcel-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: nicexcel-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for nicexcel-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bdccfefe00f3055f624db8a19b639aa6486f76dbb89aa60ec34fb2eeaeba95da
MD5 3479a7a9727c97af763248856165f432
BLAKE2b-256 ff3b5f6bd843298dcc3dd8d96102488799255c0e034f9fdfb025df679e56e581

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page