407 questions
1
vote
1
answer
2k
views
Applying multiple CSS styling options when using pandas.style.apply
I am building my own legend for a complicated figure where some lines have a hexadecimal color (e.g. #009933). To build the legend I have a column 'color' that has the same hexadecimal color as the ...
4
votes
2
answers
2k
views
Conditional formatting on Duplicates using pandas
I have a dataFrame with 6 columns. And I want to do conditional formatting on two columns of them. So my dataFrame looks like this
And I want to highlight duplicate values from College and College_F2 ...
7
votes
2
answers
6k
views
Use center diverging colormap in a pandas dataframe heatmap display
I would like to use a diverging colormap to color the background of a pandas dataframe. The aspect that makes this trickier than one would think is the centering. In the example below, a red to blue ...
15
votes
1
answer
11k
views
Pandas style background gradient not showing in jupyter notebook
I am trying to print a pandas dataframe with a background gradient for better readability. I tried to apply what I found in the docs to a simple use case, but I can't get jupyter notebook to actually ...
5
votes
2
answers
2k
views
What does the subset argument do in pandas.io.formats.style.Styler.format?
The public documentation for pandas.io.formats.style.Styler.format says
subset : IndexSlice
An argument to DataFrame.loc that restricts which elements formatter is applied to.
But looking at the ...
3
votes
1
answer
1k
views
Pandas Styler Subset column by values
I'm using the following to color the cells in a dataframe:
import seaborn as sns
cm1 = sns.diverging_palette(h_pos=130, h_neg=10, s=99, l=55, n=99, as_cmap=True)
df_s = (df.style
....
2
votes
1
answer
2k
views
Applying gradient styling to pandas DataFrame in multiple subsets
I want to apply color gradients(Green to yellow to red : based on the values) in multiple subsections of a pandas dataframe. In each of those subsections the values are going to be between 0 and 1.
So ...
8
votes
3
answers
13k
views
Display pandas dataframe with larger font in jupyter notebook
I have a small-shaped (5 rows, 3 columns) dataframe which I can display by calling df in jupyter cell. I would like to enlarge (font size) this output for presentation purpose. Is it possible?
7
votes
2
answers
2k
views
Is it possible to display pandas styles in the IPython console?
Is it possible to display pandas styles in an iPython console? The following code in a Jupyter notebook
import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(...
3
votes
3
answers
3k
views
Styling of a table in Pycharm using Pandas (df.style.applymap)?
I want to style my table with Pandas with the following example from this site:
https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
Now, the problem is, that I use Pycharm. So after ...
2
votes
1
answer
1k
views
Apply Multiple Styles to a data frame specific column
I image that this might be a complex issue. I want to have five different colors for a specific column. cld_ght in the dataframe. Here is the dataframe:
icao msg_type time dt ddd ...
1
vote
1
answer
932
views
Pandas - Styling a data frame with mixed type columns
Hello friends,
I would like to apply a styling function on a data frame that contains numeric and non numeric column types.
How can I avoid the error below?
Error:
TypeError: ("'>' not supported ...
6
votes
1
answer
2k
views
How to do Pandas Styling in PyCharm?
I can't visualize data frames with Styles in PyCharm. I'm using the following user guide:
http://pandas-docs.github.io/pandas-docs-travis/user_guide/style.html
I only get a Pandas styler object (...
2
votes
1
answer
4k
views
Pandas Styler not printing dataframe to Spyder's console as expected
I am trying to output a pandas dataframe with colored cells to the console using the pandas Styler feature. When I run code examples in Spyder 3.2.6 running python 2.7, instead of seeing the dataframe ...
2
votes
0
answers
151
views
Use color coding from pandas style object to another pandas DataFrame
I want to use the color coding from a pandas style object and apply the exact same coloring to the corresponding cells in another dataframe with the same size. The data is different in the two ...
2
votes
2
answers
2k
views
How to conditionally format pandas row groups in jupyter
I have a dataframe in pandas that looks a bit like this:
A B C
1 0.5 0.6
1 0.7 0.1
2 0.3 0.2
3 0.1 0.3
3 0.2 0.1
When you print a pandas dataframe in jupyter, ...
20
votes
3
answers
8k
views
pandas style options to latex
Pandas has two nice functionalities I use a lot - that's the df.style... option and the df.to_latex() call. But I do not know how to combine both.
The .style option makes looking at tables much more ...
1
vote
2
answers
1k
views
Styling upper triangular, lower triangular, and diagonal of a pandas dataframe
I have generated a pandas dataframe and I want to use pd.DataFrame().style to highlight some cells.
v1 v2 v3 v4 v5
v1 0 1 1 1 0
v2 0 0 1 1 1
v3 0 0 0 0 0
v4 0 0 ...
3
votes
2
answers
6k
views
Pandas style.bar color based on condition?
How can I render a Pandas df where one of the columns' style.bar.color property is computed based on some condition?
Example:
df.style.bar(subset=['before', 'after'], color='#ff781c', vmin=0.0, vmax=...
8
votes
3
answers
12k
views
Applying style to a pandas DataFrame row-wise
I'm experimenting/learning Python with a data set containing customers information.
The DataFrame structure is the following (these are made up records):
import pandas as pd
df1 = pd.DataFrame({'...
11
votes
1
answer
1k
views
Nbconvert doesn't display styler dataframe from jupyter notebook
I'm using
jupyter nbconvert --to pdf --TemplateExporter.exclude_input=True Scorecard.ipynb
to export my notebook to a pdf. Everything runs fine, but when looking in the pdf the dataframes are shown ...
4
votes
1
answer
1k
views
How to set the default Styler for a pandas DataFrame's _repr_html method?
I've got a pandas DataFrame with a column that's a url, and I've written the following formatter to present it in my notebook as a link:
def make_clickable(val):
# target _blank to open new ...
3
votes
1
answer
874
views
Force Min and Max values of colormap in pandas style
How to force min and max value range when styling a dataframe column ?
Example :
df = pd.DataFrame(columns = ['column'], data = [-1, 0, 1, 2])
df.style.background_gradient(cmap='coolwarm_r')
This ...
1
vote
0
answers
2k
views
Convert pandas.io.formats.style.Styler to image file
I am creating a conditional formatting table in Python using pandas and seaborn which gives me a pandas.io.formats.style.Styler object. I need to export this as an image file .
I cannot use imgkit, ...
5
votes
3
answers
2k
views
Pass Attributes (not functions) to python `pandas.DataFrame.style`
I have a pandas.DataFrame with values in it, say:
df = pd.DataFrame(np.random.randn(5, 3), columns=['a', 'b', 'c'])
In [160]: df
Out[160]:
a b c
0 -0.316527 -0.721590 1....
3
votes
1
answer
3k
views
Display pandas dataframe using custom style inside function in IPython
In a jupyter notebook, I have a function which prepares the input features and targets matrices for a tensorflow model.
Inside this function, I would like to display a correlation matrix with a ...
1
vote
2
answers
2k
views
Different color for each column in pandas style
I have a dataframe with several columns and a list with colors associated with each column. I want to highlight the non-blank cells in each column with the associated color.
I've tried iterating over ...
7
votes
3
answers
2k
views
Pandas style: How to highlight diagonal elements
I was wondering how to highlight diagonal elements of pandas dataframe using df.style method.
I found this official link where they discuss how to highlight maximum value, but I am having difficulty ...
0
votes
0
answers
512
views
Pandas style code not work in conda environment on spyder, packages issue?
I am trying to run this example bit of code
import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random....
0
votes
1
answer
735
views
df.style : Setting specific whole row format bold
I´m using imgkit to create a pdf with images created from html that comes from a dataframe. I need whole specific rows to be bold [rows: 0 and 7] but haven't achieved it. What am I missing?
html = df....
0
votes
1
answer
1k
views
How to apply a style to a Python DataFrame for all rows except the last one?
I am trying to apply a Bar Style to all of the data in the dataframe, except the last row, which is supposed to be the Total row.
import pandas as pd
import numpy as np
data = pd.DataFrame(np.random....
9
votes
1
answer
15k
views
Perform operations after styling in a dataframe
Whenever I try to perform any operation after styling in my code, I see this error:
AttributeError: 'Styler' object has no attribute 'drop'
In this instance I was trying to drop a column after ...
4
votes
2
answers
4k
views
How to use the .head() method of a pandas styler object?
I am working with a very big data set (18000 rows of data) which I only want to show a couple of rows such as 5 or 10 first rows. I was trying to use pandas.DataFrame().head(10) method but I am doing ...
4
votes
1
answer
4k
views
Pandas styling: Conditionally change background color of column by absolute value
I have pandas dataframe, and I would like to give a background gradient color based on absolute value.Imagine, my desire value is 6 in column A in the data frame. As number move from desire value, ...
10
votes
4
answers
3k
views
Changing style of pandas.DataFrame: Permanently?
When I change the style of a pandas.DataFrame, for instance like so
# color these columns
color_columns = ['roi', 'percent_of_ath']
(portfolio_df
.style
...
5
votes
1
answer
4k
views
Using a dataframe to format the style of another dataframe
I have one pandas dataframe that I want to style the format based on the values of another dataframe of the same shape/size. I'm trying to use applymap.
Here's an example:
t1= pd.DataFrame({'x':['A'...
1
vote
2
answers
6k
views
Why does Excel styling not work in Pandas?
import pandas as pd
import xlsxwriter
from datetime import datetime
import sys
path = sys.argv[1]
xl = pd.ExcelFile(path)
df = xl.parse("Sheet1")
df.columns = ['Nume', 'Tip de', 'Unit', 'Speciale ...
15
votes
4
answers
10k
views
Pandas style.background_gradient ignore NaN
I have the following code to dump the dataframe results into a table in HTML, such that the columns in TIME_FRAMES are colored according to a colormap from seaborn.
import seaborn as sns
TIME_FRAMES ...
6
votes
1
answer
8k
views
Pandas highlight rows based on index name
I have been struggling with how to style highlight pandas rows based on index names. I know how to highlight selected rows but when I have to highlight based on the index, the code is not working.
...
2
votes
2
answers
3k
views
Default float format for Pandas styling
I have a large number of dataframes to output in Jupyter. The columns are a mix of strings, ints, and floats. The floats need mostly to be '%.2f', but a small subset require specific formatting -- ...
20
votes
1
answer
23k
views
Is there a way to convert data frame styler object into dataframe in python
I have extracted xlsx data into pandas dataframe and used style.format to format particular columns into percentages and dollars. So now my dataframe is converted to styler object, because I need to ...
8
votes
2
answers
18k
views
Pandas: Style column header
I am using pandas styler to give some columns a background color, based on the name of the column header.
While this works as intended, the background color of the column header doesn't change.
Here ...
11
votes
1
answer
10k
views
why pandas dataframe style lost when saved with "to_excel"?
Per this example the to_excel method should save the Excel file with background color. However, my saved Excel file does not have any color in it.
I tried to write using both openpyxl and xlsxwriter ...
3
votes
1
answer
1k
views
Using iloc with pandas styler
I currently have:
def color_cell(val):
color = 'lightgreen' if val ==0 else 'white'
return 'background-color: %s' % color
s = df.style.applymap(color_cell)
Which gives the following ...
1
vote
1
answer
681
views
How to get back text ellipsis in pandas jupyter lab
I am displaying a pandas dataframe in jupyter lab. Some cells have very long text, and if I put:
df.style it will make the rows very high. Setting: df.style.set_table_styles([dict(selector="tr&...
2
votes
2
answers
7k
views
How to change the color of the first row in Excel with Pandas
I have a code where I am writing a xlsx file :
...
...
df.to_excel(finalname,index=False,header=False)
Example:
I would like to write the excel file with color, but just in the first row, like the ...
3
votes
1
answer
13k
views
Combining pandas "data frame.style" objects and outputting to html
I would like to combine pandas df.style objects that use the following methods - df.style.background_gradient and df.style.bar and export the result to html.
I'm successful when I have separate ...
7
votes
1
answer
6k
views
Export styled pandas data frame to excel
I'm trying to export a stylish data frame to an Excel file using the script below:
import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
...
3
votes
1
answer
5k
views
Compare two columns in data frame and highlight value using pandas style
I'm trying to highlight some values in some columns in data frame using pandas styles like:
import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)}...
3
votes
2
answers
1k
views
pandas DataFrame.style.render when some strings have UTF-8 characters
When using dataframe.style, accented characters are shown correctly on Jupyter:
df = pandas.DataFrame([['Madrid', 'León']], index=['Spain'], columns=['BigCity', 'SmallCity'])
df.style
...