pythonbeginner
Pandas Styled DataFrame Report
Apply conditional formatting to a pandas DataFrame for styled HTML reports with highlighting.
pythonPress ⌘/Ctrl + Shift + C to copy
import pandas as pd
df = pd.DataFrame({'Region':['North','South','East','West'],'Q1':[120,95,110,80],'Q2':[135,102,98,115],'Q3':[140,88,125,107],'Total':[395,285,333,302]})
style = (
df.style
.highlight_max(subset=['Q1','Q2','Q3','Total'], color='lightgreen', axis=0)
.highlight_min(subset=['Q1','Q2','Q3','Total'], color='#ff9999', axis=0)
.bar(subset=['Total'], color='#5fba7d')
.format('{:,.0f}', subset=['Q1','Q2','Q3','Total'])
.set_caption('Quarterly Sales Report')
)
style.to_excel('report.xlsx', engine='openpyxl')
print('Report saved')Use Cases
- executive reporting
- styled exports
- BI prototyping
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonbeginner
Pandas Pivot Table Summary
Create multi-level summary pivot tables from transactional data using pd.pivot_table.
Best for: sales reporting
#pandas#pivot-table
pythonbeginner
Pandas DataFrame Transformations
Common pandas DataFrame transformations including column operations, type casting, and string methods.
Best for: Cleaning raw data files for analysis
#pandas#dataframe
pythonbeginner
Pandas DataFrame Filtering Techniques
Filter DataFrames using boolean masks, query syntax, isin, between, and string matching methods.
Best for: Extracting subsets of data for reporting
#pandas#filtering
pythonintermediate
Pandas GroupBy Aggregation Examples
GroupBy operations with multiple aggregations, named aggregations, and transform for DataFrame analysis.
Best for: Sales reporting by region and time period
#pandas#groupby