407 questions
1
vote
2
answers
1k
views
Conditionally format cells in each column based on columns in another dataframe
I have a dataframe that contains threshold values for 20+ elements that's formatted like so
df1:
Li
Se
Be
Upper
30
40
10
Lower
10
5
1
I have another dataframe which contains values for those elements
...
2
votes
3
answers
858
views
Pandas highlight specific number with different color in dataframe
I'm trying to highlight specific number with different color in my dataframe below:
import pandas as pd
df = pd.DataFrame([[10,3,1], [3,7,2], [2,4,4]], columns=list("ABC"))
I can highlight ...
0
votes
1
answer
961
views
How can I format index text data using pandas.styler
Looking to create a table like this in Jupiter Notebook based on a pandas DataFrame. While styler has much on how to format data, much typically done in excel/word is formatting text to make it ...
1
vote
2
answers
403
views
Pandas add a new column with a string where the cell match a particular condition
I'm trying to apply Pandas style to my dataset and add a column with a string with the matching result.
This is what I want to achieve:
Link
Below is my code, an expert from stackflow assisted me to ...
2
votes
1
answer
751
views
Create a new column after dataframe gets df.style
I'm trying to add a new column after dataframe gets df.style.
However, I got an error message:
'Styler' object does not support item assignment
Below is my code:
import pandas as pd
df = pd....
1
vote
1
answer
3k
views
Python Pandas style highlight specific cells for each column with different condition
I'm trying to highlight specific cells for each column with different condition which their value matches the condition for each row.
Below image is what I want to achieve:
The table I attempt to ...
1
vote
1
answer
1k
views
Seaborn heatmap only apply to subset of columns
I tried different seaborn functions and pandas style functions. I want to apply a heatmap with center=0 (positive value gets red heatmap, negative values gets blue heatmap) while keeping all the ...
1
vote
2
answers
165
views
How to use Pandas styler to implement Excel-like conditional formatting?
I have 2 columns that I want to compare (SO Status & Past_Week_SO).
I want to show "Past_Week_SO" with red color when the data is different from the "SO Status".
This is my ...
0
votes
1
answer
460
views
Is there a way to use CSS column combinator in Pandas DataFrame Styling?
I am using the Pandas DataFrame styler and want to make every other column (based on the first level of a multi index rather than hard code) have a gray background. I know that with CSS you can use ...
1
vote
2
answers
262
views
Rounding within a conditional format function
I have the following code that formats my df correctly, only it changes the rounding of my values from being 2 dp to adding 4 zeros to each value. Anyone know how to adjust the function to not add the ...
0
votes
1
answer
84
views
how to convert groupby object which has no aggregate function applied on it, to a new dataframe
Updated:
I have a huge dataframe, providing small version of it.
header = [np.array([' ',' ',' ','X','X','Y','Y']),
np.array(['A','B','C','D','E','F','G'])]
df = pd.DataFrame(columns=header)
...
0
votes
1
answer
572
views
Styling in Pandas multi-criteria
On a Pandas dataframe I would like to apply a style on a specific column, on a multi-criteria taken from different columns values.
table =
product sales revenues
fruit 10 6
eggs ...
0
votes
1
answer
854
views
is there any way i can apply another style on a styler in pandas
I have NAN values in my dataframe columns and i need to replace it with empty string. I need to perform subtraction on these columns, so when replacing with empty string i am getting error:
...
2
votes
3
answers
11k
views
Styling the background color of pandas index cell
I want to change the background styling color of the pandas table.
Example:
df = pd.DataFrame({
'group': ['A','B','C','D'],
'var1': [38, 1.5, 30, 4],
'var2': [29, 10, 9, 34],
'var3': [8, 39, 23, 24],
'...
1
vote
1
answer
222
views
Numbers got unrounded after applying pandas styles
I rounded numbers before applying pandas styles, it worked fine. However, after applying styles, the numbers got unrounded. I don't get it.
example data
d = {'col1': ['a', 'b', 'c']*2, 'col2': [1.111, ...
4
votes
2
answers
8k
views
Pandas Style conditional formatting (highlight) on text
I am trying to highlight the single whole cell in pandas based on text. For example, if Recommend is 'SELL', I want to highlight in red and green for 'BUY'. Appreciate if someone can guide me on this.
...
0
votes
1
answer
2k
views
Pandas MultiIndex with to_html
I am generating an email report using pandas –to_html function. I am looking for solutions and struck at a point(screenshot attached) where I want to combine cell values in the dataframe(just like ...
1
vote
1
answer
416
views
coloring rows in pandas based on integer index
I would like to color my rows based on my list of integer such that:
if my integer is = [3, 10, 12]
the coloring of pandas style should be:
I was trying to do what How to highlight both a row and a ...
0
votes
2
answers
1k
views
Pandas style based on logarithm of value
I'd like to style a Pandas DataFrame display with a background color that is based on the logarithm (base 10) of a value, rather than the data frame value itself. The numeric display should show the ...
5
votes
3
answers
35k
views
Styler object has no attribute style
This is a follow up question on applying background color to a dataframe based on condition
I am able to apply style based on the below:
f = lambda v: 'background-color: %s' % 'green' if v=='col' else ...
0
votes
1
answer
460
views
Generate html from pandas dataframe
Pardon me I am new to handle html through pandas and having trouble generating required format
I have dataframe like below
Category Date Avg Price - growth (%) Profit Overall profit
A ...
1
vote
1
answer
4k
views
Applying style to values of only one column in dataframe
I want apply some filter conditions on specific cols. Based on filter I want to highlight that cell.
I took this example from another post:
styled = (df.style
.applymap(lambda v: '...
2
votes
1
answer
1k
views
How to color dataframe based on each group?
I have a dataframe as below
import pandas as pd
import seaborn as sns
import numpy as np
df = sns.load_dataset("diamonds")
df.head()
carat cut color clarity depth table price ...
2
votes
1
answer
1k
views
Pandas: Style a specific cell based on another column in a dataframe
I want to highlight the cells based on the values of another column in a dataframe. Like in the below example, I want to highlight the prodkey1 and product1 cells if the value of p1_ourproduct is ...
3
votes
2
answers
781
views
Style rows of a dataframe based on column value
I have a csv file that I'm trying to read into a dataframe and style in jupyter notebook. The csv file data is:
[[' ', 'Name', 'Title', 'Date', 'Transaction', 'Price', 'Shares', '$ Value'],
[0, 'Sneed ...
1
vote
1
answer
4k
views
Using highlight_max and highlight_min from pandas.io.formats.style.Styler at the same time
I want to highlight the maximum value in each row as green and the minimum value as red.
import numpy as np
import pandas as pd
value = np.random.normal(size=(5,5)) #Generate random data
df = pd....
2
votes
1
answer
3k
views
How to apply pandas style to multiple columns
I have the following dataframe:
df=pd.DataFrame({'c1':['a','b','c'],
'c2':['aa', 'bb','cc'] })
And I have the following function to color cells:
def color_cell(cell, c):
if cell ...
8
votes
1
answer
3k
views
pandas styling doesn't display for all rows in large dataframes in Chrome or Edge
Update:
The issue seems to be with displaying the HTML with styling rendered by pandas in Google Chrome and Microsoft Edge.
JupyterLab in Firefox correctly displays all of the styled rows and ...
1
vote
1
answer
2k
views
How to set pandas dataframe background color based on another column
I have a dataframe 'df' like this
How do I s set he background color of the column 'wt' based on the column 'item'.
If 'item' is 'apple', the value in the 'wt' column should have a background colour ...
0
votes
2
answers
2k
views
How to apply style selectively to rows of specific columns?
I want to flag the anomalies in the "desired" columns (desired_D to desired_L). Here, an anomaly is defined as any value <1500 and >400000 in each row.
See below for the dataset:
...
0
votes
2
answers
3k
views
Why does the export of a styled pandas dataframe to Excel not work?
I would like to apply the same background color to cells that have for each PEOPLE instance the name and the related name. I have tried to df.style.applymap, it does not return an error but it does ...
4
votes
2
answers
7k
views
How to hide the column labels after using .style
How do I hide the column labels via pandas style? There is a hide_index() method that removes the index row, unfortunately the hide_column() label removes the entire column (both the header and the ...
0
votes
1
answer
489
views
Highlight pandas dataframe cells contained in a list
I want to highlight dataframe cells contained in a specific list, to get better performance, I want this only happens to specific column.
I understand we should set df.style background-color: yellow ...
4
votes
2
answers
6k
views
Formatting numbers after coloring a dataframe using Styler
I created a DataFrame in pandas for which I want to color the cells using a color index (low values red, high values green). I succeeded in doing so, however the coloring prevents me to format the ...
5
votes
1
answer
2k
views
styling a pandas dataframe in python makes the float values have more zeros after the decimal point
this is my style code to make positive numbers appear green and negative numbers appear red
if i just print out df it would show the numbers like this:
25.72,36.28,0.17
with the style however they are ...
0
votes
1
answer
215
views
Currency in Pandas Styler (rs)
Want to pandas style Currency : Rupee \u20B9 (How to print currency symbol and an n-digit decimal number right aligned in Python)
format_dict = {'Premium Per Rep':'{0:,.0f}'}
f1=f.style....
4
votes
1
answer
5k
views
permantly apply style.format to a DataFrame
I went to apply a style.format to one of my columns in the df (to add commas), but after calling df second time –– it seems that the style.format is not permanent? When I do assign the style.format to ...
1
vote
1
answer
1k
views
How to change font-weight of the text for the row in dataframe that matches the criteria which contains a mixture of float and string values?
data = {'Rest (N=11570)': {4: '7369 (62.28%)', 1: '7016 (59.98%)', 37: '734 (6.14%)', 40: '9829 (79.09%)', 43: '37 (2.42%)', 5: '3080 (25.29%)', 6: '1273 (9.43%)', 12: '6992 (62.61%)', 15: '777 (5.47%)...
7
votes
3
answers
10k
views
Pandas Style: Draw borders over whole row including the multiindex
I'm using pandas style in a jupyter notebook to emphasize the borders between subgroups in this dataframe:
(technically speaking: to draw borders at every changed multiindex but disregarding the ...
0
votes
3
answers
3k
views
How to resolve this error when trying to use Pandas Styling?
I am running Python 3.6.5 and Pandas 0.25.2.
On attempting to style a pandas dataframe I am getting a specific error which can be generated by simplifying to this code:
import pandas as pd
import ...
3
votes
1
answer
1k
views
Filter Pandas DataFrame based on style
This documentation shows how to apply styles pandas.DataFrame. How can we select the yellow cells from df?
df = pd.DataFrame({"A": [1, 2, 3, 4, 5], "B": [1, 7, 14, 5, 3]})
def ...
2
votes
1
answer
1k
views
Is there a python function to color/style multi-index levels?
I have defined a function to get value_counts for each column with Count, Percentage % as below:
import pandas as pd
import seaborn as sns
import numpy as np
from IPython.display import display
df = ...
0
votes
1
answer
217
views
Pandas Styler - CSS limit reached
I have a webserver that displays tables of data with some formatting. The formatting is colouring certain cells. The tables are stored as dataframes and the formatting is applied using a pandas styler....
3
votes
1
answer
10k
views
How to use pandas.style with streamlit
I am creating an app with Streamlit and I wish to print out a pandas dataframe in which I can change the background color of each cell of the dataframe. I found out that this is supported by pandas ...
1
vote
0
answers
219
views
3 color code - conditional formatting Excel cells with pandas
I am trying to edit an excel file using pandas. What I would like to do is, for a chosen column and a specific threshold have all the cells in that column with values lower than the threshold to be ...
3
votes
0
answers
328
views
Pandas style-dataframe has multi-index columns misaligned
I need to style a Pandas dataframe that has a multi-index column arrangement. As an example of my dataframe, consider:
df = pd.DataFrame([[True for a in range(12)]])
df.columns = pd.MultiIndex....
0
votes
1
answer
1k
views
How to extend Pandas base Styler template
Hi so I'm working on writing a custom jinja template that inherits from Pandas base template.
My default template looks as
{% extends "html.tpl" %}
{% block table %}
<style type="...
0
votes
2
answers
2k
views
Pandas Styling: Conditional Formatting
I am apply the following formatting to the pandas data frame.
The data is as follow:
{'In / Out': {'AAA': 'Out',
'BBB': 'In',
'Total1': 'Out',
'CCC': 'In',
'DDD': 'In',
'Total2': 'In'},
'...
5
votes
2
answers
17k
views
pandas DataFrame style lost table border
I'm following instructions at https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
to set up style for my data frame to become html.
It worked well, except that the table's border of ...
0
votes
1
answer
974
views
Apply Pandas Styler to MultiIndex list
I have a multi-index pivot table that I am making from a dataframe as shown below:
pivot_summary = pd.pivot_table(df, index=['Team', 'Associate Name'], columns=['Date'], values=['Call Transfers'], ...