There are only [3,4,5,6,8] values for Cylinders in Auto.csv
, but when I created a bar plot using plotly, I see that there is one extra value for Cylinder over X-axis which is 7.
How to eliminate that additional point?
Thanks in advance.
There are only [3,4,5,6,8] values for Cylinders in Auto.csv
, but when I created a bar plot using plotly, I see that there is one extra value for Cylinder over X-axis which is 7.
How to eliminate that additional point?
Thanks in advance.
You could change your axis type to categorical
which prevents Plotly from filling your "missing" values.
fig.update_xaxes(type='category')
import pandas as pd
import plotly.express as px
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv')
df_mean = df[['cyl', 'mpg']].groupby('cyl').mean().reset_index()
fig = px.bar(df_mean, 'cyl', 'mpg')
fig.update_xaxes(type='category')
fig.show()