StyleFrame
raw JSON → 4.2 verified Mon Apr 27 auth: no python
A library that wraps pandas and openpyxl to allow easy styling of DataFrames in Excel. Current version: 4.2. Supports Python 3.6+ (dropped Python 3.4/3.5 in 4.0.0). Regular releases; last update January 2022.
pip install styleframe Common errors
error ImportError: cannot import name 'StyleFrame' from 'StyleFrame' ↓
cause Package was renamed to lowercase 'styleframe' in v3.0.1. Old import path no longer works.
fix
Use
from styleframe import StyleFrame. error AttributeError: module 'styleframe' has no attribute 'ExcelWriter' ↓
cause Before v4.1, ExcelWriter was not exposed at module level.
fix
Use
from styleframe import StyleFrame and access StyleFrame.ExcelWriter. Warnings
breaking Package name changed from 'StyleFrame' to 'styleframe' (all lowercase) in v3.0.1. Old imports will fail. ↓
fix Use `from styleframe import StyleFrame` instead of `from StyleFrame import StyleFrame`.
breaking Python 3.4 and 3.5 support removed in v4.0.0. ↓
fix Upgrade to Python 3.6+.
deprecated Using non-openpyxl engine in `to_excel` raises TypeError since v4.1. ↓
fix Ensure you are using openpyxl engine. Default is openpyxl.
gotcha When using `to_excel` with `header=False`, rows may be misaligned before v4.0.0. ↓
fix Upgrade to v4.0.0+.
gotcha `best_fit` argument in `to_excel` caused an error on empty DataFrames before v4.2. ↓
fix Upgrade to v4.2 or avoid using best_fit on empty DataFrames.
Imports
- StyleFrame wrong
from StyleFrame import StyleFramecorrectfrom styleframe import StyleFrame - Styler
from styleframe import Styler - utils
from styleframe import utils
Quickstart
from styleframe import StyleFrame, Styler, utils
import pandas as pd
df = pd.DataFrame({'A': [1, 2], 'B': ['x', 'y']})
sf = StyleFrame(df)
styler = Styler(bg_color=utils.colors.yellow, bold=True)
sf.apply_style_by_indexes(sf.index, styler)
sf.to_excel('styled.xlsx').save()
print('Excel file created.')