You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plotly Express gives a KeyError when using a subselection of a dataframe with a categorical column. The categorical column is useful for custom ordering of values, but sometimes you only want to plot a subset of that dataframe. When not all the values of the Categorical column are present in the subselection, Plotly Express gives an error:
df=pd.DataFrame({
"x": [0, 0, 1, 0, 1],
"Value": [10, 5, 7, 3, 8],
"Category": pd.Categorical(["one", "two", "one", "three", "three"], categories=["one", "two", "three"], ordered=True)
})
px.scatter(
df[df["Category"].isin(["one", "three"])], # Works fine with just `df` herex="x",
y="Value",
color="Category"
)
The text was updated successfully, but these errors were encountered:
Plotly Express gives a KeyError when using a subselection of a dataframe with a categorical column. The categorical column is useful for custom ordering of values, but sometimes you only want to plot a subset of that dataframe. When not all the values of the Categorical column are present in the subselection, Plotly Express gives an error:
The text was updated successfully, but these errors were encountered: