Black Lives Matter. Please consider donating to Black Girls Code today.

Rename the Categories Value (X-axis) in Plotly Express

import plotly.express as px

bar_chart = px.histogram(df, x="column_1", y="y_values", histfunc = "sum")

my dataframe has 2 columns: df[“column_1”] and df[“column_2”]

I wonder if it is possible to rename my X-axis Categories value to values in df[“column_2”]

The reason why I dont want to set my x = “column_2” in plotly express is because my column_2 might have duplicated values (column_1 is unique values).

Also I need to group my column_1 values with sum hence I’m using histogram function.

Hence, I want to group by column_1 not column_2 as column_1 will give me 2 unique categorical values whereas column_2 will give me only 1 unique categorical value.

Is there any workaround for this? Thank you!

** To give you all a better context of “column_1” and "column_2’:

The diagram above illustrates what I want for the graph. I would like to group data by “column_1” but labels to be show as “column_2” (as circled in red). Notice that “column_2” is not unique but “column_1” is unique.

Hi @steve_13 welcome to the forum! It’s not really clear to me what you’re trying to do sorry. Maybe a schematic drawing could help?

Hi there, I had included the drawing in my post :slight_smile: