Skip to content

Pandas style.bar(align='mid') does not make sense. #26070

Closed
@sorenwacker

Description

@sorenwacker

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np
N = 10
df = pd.DataFrame(np.random.normal(size=(10, N))+np.arange(N)*100, columns=range(N))
df.style.bar(align="mid", color=['pink', 'lightgreen'], axis=0)

Problem description

With align='mid' I would expect the middle to be the mean. Essentially, as a tool to visualize the variance.

The dataframe above contains 10 columns with random numbers. To the n's column n*100 is added. So, column-wise, I would expect pretty similar output cause the mid should be the mean of each column.

But because for columns that contain only positive or (only negative) values, the alignment is done differently. The way it is done right now you cannot see anything for e.g. column 8.

An alignment method where the mean is always used would be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions