0

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.

Following is the screenshot of the code executed

kHarshit
  • 11,362
  • 10
  • 52
  • 71

1 Answers1

0

You could change your axis type to categorical which prevents Plotly from filling your "missing" values.

fig.update_xaxes(type='category')

enter image description here

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()
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99