"Colorize Your Data: Pandas to Excel with Vibrant Colors"

Martha Jun 07, 2026

Are you tired of manually coloring cells in Excel? Pandas, a powerful data manipulation library in Python, offers an efficient way to add color to your data. By leveraging pandas' styling capabilities, you can enhance the visual appeal of your data and make it more understandable. Let's explore how to apply colors to your Excel data using pandas.

Master Pandas with 10 Essential Operations | Anas Riad posted on the topic | LinkedIn
Master Pandas with 10 Essential Operations | Anas Riad posted on the topic | LinkedIn

Why Use Colors in Excel with Pandas?

5 lesser-known pandas tricks | Towards Data Science
5 lesser-known pandas tricks | Towards Data Science

Adding color to your Excel data can significantly improve readability and highlight important information. It's particularly useful when dealing with large datasets or complex analyses. By applying colors, you can:

  • Draw attention to specific data points or trends
  • Differentiate between categories or groups
  • Make your data easier to scan and understand
Change order of Columns in a Pandas DataFrame
Change order of Columns in a Pandas DataFrame

Getting Started with Pandas and Excel

Before you begin, ensure you have pandas and openpyxl installed. If not, you can install them using pip:

♥ 𝐹𝒶𝓃𝓉𝒶𝓈𝓎 𝒫𝑒𝓉𝓈 ~ 𝒜𝐼 ♥ .•°°•.
♥ 𝐹𝒶𝓃𝓉𝒶𝓈𝓎 𝒫𝑒𝓉𝓈 ~ 𝒜𝐼 ♥ .•°°•.

pip install pandas openpyxl

Reading Excel Files with Pandas

First, let's read an Excel file using pandas. We'll use the read_excel function from the pandas.io.excel module.

panda
panda

import pandas as pd

df = pd.read_excel('your_file.xlsx')

Applying Colors to Excel Data with Pandas

Using Python Pandas With Excel
Using Python Pandas With Excel

Pandas provides the style attribute to apply formatting to dataframes. To add color, you can use the applymap function with a custom color function. Here's how to do it:

Applying a Single Color

무지개에 예쁨과 판다에 귀여움
무지개에 예쁨과 판다에 귀여움
a panda bear holding a game controller in its paws with glowing neon lights around it
a panda bear holding a game controller in its paws with glowing neon lights around it
Будьте внимательны, скорее всего, календарь не правильный, это же ИИ
Будьте внимательны, скорее всего, календарь не правильный, это же ИИ
a panda bear sitting on top of a colorful object in the sky with planets around it
a panda bear sitting on top of a colorful object in the sky with planets around it
Pandas and Key Features
Pandas and Key Features
two pandas are sitting on bamboo stalks and one is looking up at the sky
two pandas are sitting on bamboo stalks and one is looking up at the sky
Pandas plotting guide for beginners
Pandas plotting guide for beginners
Будьте внимательны, скорее всего, календарь не правильный, это же ИИ
Будьте внимательны, скорее всего, календарь не правильный, это же ИИ
a panda bear sitting on top of a tree branch
a panda bear sitting on top of a tree branch
the important method to improve data flow in pandas package, with text and diagrams
the important method to improve data flow in pandas package, with text and diagrams
a panda bear sitting on top of a pile of rainbow colored bubbles in front of a colorful background
a panda bear sitting on top of a pile of rainbow colored bubbles in front of a colorful background
a panda bear holding onto a bamboo stick with a flower on it's head
a panda bear holding onto a bamboo stick with a flower on it's head
the pandas are eating and playing with each other in their own houseplants
the pandas are eating and playing with each other in their own houseplants
a painting of a panda bear sitting on the ground with flowers in front of it
a painting of a panda bear sitting on the ground with flowers in front of it
a panda bear holding a paintbrush and palette
a panda bear holding a paintbrush and palette
a panda bear is surrounded by roses and diamonds
a panda bear is surrounded by roses and diamonds
three pandas are floating on small rafts in the water with rocks and flowers
three pandas are floating on small rafts in the water with rocks and flowers
a little panda bear sitting on top of a car with sparkles in the background
a little panda bear sitting on top of a car with sparkles in the background
the pandasheet data cleaning manual is shown in green and white, with an image of
the pandasheet data cleaning manual is shown in green and white, with an image of
several panda bears are sitting in the grass with clover leaves on their heads, and one is
several panda bears are sitting in the grass with clover leaves on their heads, and one is

Let's apply a light blue color to the entire dataframe.

def color_blue(val):

return 'background-color: lightblue'

df.style.applymap(color_blue)

Applying Colors Based on Conditions

You can also apply colors based on conditions. For example, let's highlight values greater than 100 in red:

def color_red(val):

return 'background-color: red' if val > 100 else ''

df.style.applymap(color_red)

Applying Colors to Specific Columns

To apply colors to specific columns, you can use the apply function with a custom color function. Here's how to highlight even-indexed rows in a column named 'A':

def color_even(val, color='lightgray'):

return 'background-color: %s' % color if val % 2 == 0 else ''

df.style.apply(color_even, subset=['A'])

Exporting the Styled Dataframe to Excel

After applying colors, you can export the styled dataframe back to an Excel file using the to_excel function with the engine='openpyxl' argument:

df.style.applymap(color_blue).to_excel('styled_file.xlsx', engine='openpyxl')

Conclusion

In this article, we've explored how to apply colors to your Excel data using pandas. By leveraging pandas' styling capabilities, you can enhance the visual appeal of your data and make it more understandable. Whether you're highlighting specific data points, differentiating between categories, or making your data easier to scan, adding color can significantly improve the readability of your Excel files.