407 questions
5
votes
3
answers
189
views
How to use Pandas style objects to format values with a hyperlink based on the index?
I want to format a Pandas DataFrame with a hyperlink based on the index.
import pandas as pd
df = (pd.DataFrame([dict(food='bananas', count=33, color='yellow'),
dict(food='apples',...
0
votes
0
answers
55
views
Apply float styling to specific rows in pandas dataframe [duplicate]
I've created a large dataframe with a smaller dataframe that represents a summary of some calculations run on the larger dataframe. This will find certain percentages, max/min of some columns, etc. I'...
0
votes
2
answers
103
views
How to display a random sample from a styled DataFrame?
I often want to view a random sample of k rows from a DataFrame rather than just the head/tail, for which I would use df.sample(k).
When I chain on .style to this sample, the styler will only see the ...
1
vote
1
answer
161
views
Alternate background colors in styled pandas df that also apply to MultiIndex in python pandas
SETUP
I have the following df:
import pandas as pd
import numpy as np
arrays = [
np.array(["fruit", "fruit", "fruit","vegetable", "vegetable", &...
1
vote
1
answer
47
views
How to style all cells in a row of a specific MultiIndex value in pandas
SETUP
I have the following df:
import pandas as pd
import numpy as np
arrays = [
np.array(["fruit", "fruit", "fruit","vegetable", "vegetable", &...
1
vote
2
answers
120
views
How to style groups of rows differently based on a column's value with Pandas Styler
What I am trying to accomplish:
I have the following dataframe, df:
data = {'person': {0: 'a',
1: 'a',
2: 'a',
3: 'a',
4: 'a',
5: 'a',
6: 'b',
7: 'b',
8: 'b',
9: 'b',
10: 'b',
11:...
3
votes
2
answers
417
views
Pandas dataframe title/caption in plain text to_string output?
As an example:
import pandas as pd
df = pd.DataFrame({
"Hello World": [1, 2, 3, 4],
"And Some More": [10.0, 20.0, 30.0, 40.0],
})
df_caption = "Table 1: My Table"
df....
1
vote
1
answer
39
views
Why can't I add more formatting options to my dataframe?
In my code I am able to white out N/As. You will see this near the bottom of the code.
I would also like to add additional formatting to specific columns whereby they are formatted as USD Currency ($,...
3
votes
2
answers
1k
views
Styling negative numbers in pandas
I have a dataframe that I am exporting to Excel. I would also like to style it before the export.
I have this code which changes the background color and text color and works fine, but I would like to ...
0
votes
3
answers
351
views
How to make a specific header in italics using pandas?
I am using Pandas to make an HTML table. I want one of my column headers to be in italics. I can put the whole of a header row in italics like this:
import pandas as pd
col = pd.MultiIndex.from_arrays(...
-1
votes
1
answer
66
views
Copying the ExcelFormat styling of a DataFrame
When using the to_excel function of pandas DataFrames, the formatter ExcelFormatter styles the cells in a nice way (for example, it merges repeated multiindex columns). Is it possible to copy this ...
0
votes
1
answer
420
views
Parenthesis in negative numbers on Pandas Styler object
So I got a 3x3 dataframe that looks like this:
import pandas as pd
df = pd.DataFrame([[-232.3,43.1,"hre"],[-245.7,-943.7,"jtr"],[956.3,435.2,"fgjh"]], columns=list("...
0
votes
1
answer
57
views
how do you style data frame and write to excel in pandas
I need to change the background's color of the dataframe headers to orange:
My df looks like this:
Campus Server Port
AZ server12 Eth1
AZ1 server12 Eth2
AZ2 server23 ...
1
vote
1
answer
48
views
How to highlight rows or string in one dataframe based off the values of a column in a different datafame?
I want to be able take vales from one column of dataframe and find the exact same values in another dataframe to either highlight the whole row or just the string (whatever is easier/possible).
...
2
votes
1
answer
198
views
How to combine different styles in one styler map?
I have a dataframe with 3 kind of data types - int64, float64 and object (string). How to apply format for two different data types in one function?
Sample:
def abc_style_format(cell_val):
default ...
1
vote
2
answers
123
views
How to highlight non-main diagonal elements
I was wondering how to highlight diagonal elements of pandas DataFrame using df.style methods.
I already found out how to do it with the main diagonal, but can't manage to highlight the one which ...
0
votes
1
answer
936
views
df.style.format() having no effect on dataframe
I'm using Jupyter Notebook and I have a DataFrame with df.shape = (18,7). All columns are of float64 dtype :
def currency_format(x):
return "${:,.0f}".format(x/1000000)
dfResults....
0
votes
1
answer
379
views
keep all formatting when exporting to excel
I have dataframe df_brands and I want to format this df and export to excel-file, but I have a problem
I have df_brands:
and I format this df:
and after this I want save this formatted df in excel-...
1
vote
1
answer
79
views
How to alternate colours everytime my value changes in a specific column?
I want to switch the colour of my entire row everytime the value in column 'column2' changes.
Here is an example of how I am trying it to look like:
If it helps here is my dataframe:
df1 = pd....
0
votes
1
answer
232
views
wrap one pandas column heading and another column contents simultaneously
I've had two styling things clash in a pandas dataframe in jupyter notebook and cancel each other out.
One column has a very long column heading, the other column has a small column heading but the ...
1
vote
1
answer
648
views
Divergent background gradient setting the intermediate color to value "0"
My goal is to get a df.style with background gradient going from red to white (intermediate color) to green. The thing is I want to set white color to the value 0. So, if we had a column with values ...
-1
votes
2
answers
663
views
how do you force write pandas styles to excel file in Pandas
I have a data frame like this:
df
Server CPU_Usage Memory Usage
Prod1 80 30
Prod2 70 10
Prod3 20 12
I need to apply Pandas Style to show % sign next to the numbers ...
0
votes
2
answers
258
views
how do you remove text from Pandas styled object while keeping the style in place
I have a styled object that some of the cells have nan values. I need to remove the nan values while I keep the style in place.
if I do this:
new_df.data.replace(np.nan, '', regex=True)
this removes ...
-2
votes
1
answer
71
views
how do you style data frame in Pandas
I have this data frame:
df
Server Env. Model Percent_Utilized
server123 Prod Cisco. 50
server567. Prod Cisco. 80
serverabc. Prod IBM. 100
...
2
votes
1
answer
81
views
how do you modify styled data frame in Pandas
I have this data frame:
df
Server Env. Model Percent_Utilized
server123 Prod Cisco. 50
server567. Prod Cisco. 80
serverabc. Prod IBM. 100
...
1
vote
1
answer
196
views
df.style is not working in pydroid3, a python IDE for Android mobile
I'm trying to highlight largest value in each column of my DataFrame. It's working well in my laptop but not in my pydroid3 mobile app...
data = {'Column1': [10, 15, 8],
'Column2': [20, 5, 12],
...
0
votes
1
answer
667
views
Trying to change column width of dataframe with df.style.set_properties, but does not work
I am trying to change the column width of my dataframe through the use of pandas' style and set_properties, but the width parameter is the only thing that doesn't seem to work while the rest of the ...
1
vote
0
answers
166
views
Dataframe.to_latex create a multilevel header in latex when the index have a name
I have a pandas DataFrame that I styled to generate a latex table with it.
I notice that when I don't name the index, the results is a one line header with the first column empty
Unnamed index
...
0
votes
1
answer
243
views
Unable to correctly subset a multiindex column to apply pandas styler
I have the following dataframe:
import pandas as pd
import numpy as np
df = pd.DataFrame(
{
("A", "Current"): [1, 2, 3],
("A", "Prev"): [1, ...
0
votes
1
answer
85
views
How to highlight particular cells in colour using groupby and styler
I have a df as follows
Group Date Data1 Data2
A 01-01-2023 22 23
A 01-02-2023 24 20
A 01-03-2023 10 20
A 01-04-2023 30 32
B 02-03-2023 24.5 26.5
B 02-04-2023 26.5 23....
1
vote
1
answer
37
views
Applying styler to table replaces the values with style as plain text
I have a very huge dictionary which I am trying to highlight few rows with matching keys. To highlight specific rows in the HTML table generated from a dictionary, I am using below code. After running ...
1
vote
1
answer
125
views
Python: How to apply pandas styling for a unique ID based on comparison between two days?
I am trying to color cells based on the value of the specific cell. I have a dataframe that includes data for the same product for two different dates. I want to highlight the cell for the latest date ...
0
votes
1
answer
220
views
How to input data image dataset as dataframe?
I have a dataset, that contains only images. I need to input it as a dataframe.
I tried to do this with load_files function from sklearn:
data = load_files(path)
And tried to create a dataframe with ...
1
vote
2
answers
611
views
is there a way to color specific text in pandas column (not whole column only specific text)
How to color a specific text a in pandas df ?
The following code colors the whole cell. I'm trying to color only a specific word in the column.
import pandas as pd
# Create a DataFrame (sample data)
...
0
votes
3
answers
710
views
styling a pandas table and merging 2 dataframes
I wanted to style a pandas table, but I'm not able to reshape it every other row, color it this way or set borders for it. I'd be thankful if anyone helps me with this. I uploaded both tables below. ...
1
vote
2
answers
40
views
How can I remove a column in a pandas DataFrame and make another column clickable, redirecting to a URL in the same row?
Suppose I have a pandas DF with the below data:
`data = {
'Crypto': ['ARB', 'ETH', 'ETH'],
'Position': ['Long 10.0X', 'Short 25.0X', 'Short 2.0X'],
'Size Crypto': ['1,075,328.5024 ARB', '...
1
vote
2
answers
539
views
Pandas styler gradient vmin vmax from another column
I have a dataframe df which looks like following.
Parameter M1 M2 M3 Relative Vmin Relative Vmax
0 P1 1.5 3.1 3.0 1.0 100.0
1 P2 2.2 4.1 4.2 ...
0
votes
1
answer
78
views
Trying to create a heatmap of Home Wins/Away Wins/Draws
Using the Kaggle EPL dataset and epl=df.dropna().reset_index(drop=True).
I'm trying to create a heatmap similar to this:
The columns needed to create the heatmap from the dataset would be as follows:
...
0
votes
1
answer
264
views
Dropping columns used as condition when highlighting the column in Pandas [duplicate]
I have highlighted pandas dataframe using conditional statement (highlight one column as yellow if other column value is True). Before exporting to Excel I want to remove the conditional column I used....
1
vote
2
answers
843
views
Pandas styling of rows
Hi I am trying to style a pandas data frame based on some condition and write the output to excel. I followed the solution here and got it partially done: applying-style-to-a-pandas-dataframe-row-wise....
1
vote
1
answer
453
views
How to apply style.applymap to a DataFrame based on condition in another DataFrame
I have two dataframes the same size (3 by 3), one is Logical (True/False) and the other is numerical:
My script allows the user to input a specific coordinate from the Logical Matrix in order to ...
0
votes
1
answer
858
views
How to style a pandas pivot table dataframe?
I have created a pivot table dataframe and I want to add custom styling to it. I want to iterate over each row and column values and compare the data value from the previous column value. If the value ...
0
votes
3
answers
801
views
Applying pandas styler to format dataframe header in latex
I am trying to get the latex file for the following table/dataframe:
df = pd.DataFrame(np.random.rand(10,2)*5,
index=pd.date_range(start="2021-01-01", periods=10),
...
3
votes
2
answers
2k
views
Pandas Sticky Column Headers using Styler not working (sticky index rows works great)
I am using pandas 1.5.3 in Flask. This code creates a sticky index column but not sticky column headers:
bigdf = pd.DataFrame(np.random.randn(100, 100))
dfhtml = bigdf.style.set_sticky(axis="...
0
votes
1
answer
177
views
Pandas style function to set multiple row attributes for matches to column value
For rows in a pandas dataframe that have a given value in a given column, I cannot figure out how to make those rows both colored yellow and bold type.
The following coding successfully colors a row ...
3
votes
1
answer
288
views
Remove blank line when displaying MultiIndex Python dataframe
I have a MultiIndex Python Dataframe displaying like this:
What can I do to pull up the index names ("index1", "index2") and delete the empty row above the dataframe values to get ...
1
vote
0
answers
48
views
Dataframe style is not getting exported to excel
I tried styling my dataframes
df.style\
.applymap(add_color,\
subset=[column names])\
.format('{0:,.0f}',na_rep='-')
I tried to export this style after storing it to excel but ...
1
vote
1
answer
177
views
How does one remove internal borders for specified cells with Pandas Styler?
I would like to add borders to specific cells and when adjacent, border the adjacent group without internal borders.
Here is my code so far...
import pandas as pd
df = pd.DataFrame({"TransNo&...
1
vote
1
answer
69
views
Highlight differences in words in df cells
I have a df that looks like this:
df = pd.DataFrame({'Before':['one three four', 'apple banana milk'],
'After': ['one two three four five', 'soda banana apple juice milk'],
...
2
votes
1
answer
82
views
Style background color of dataframe cells based on rule
I'm trying to style a simple multiplication table. I have the following rule, and if a cell doesn't satisfy it, I must colorize it in a different color.
Example 1: Given numbers 10 and 11, the rule ...