Question
Use Pandas index in Plotly Express
Plotly Express allows me to easily plot a pandas dataframe, as explained in their examples. Rather than using a named column for x and a named column for y, I would like to use the dataframe's index for x and a named column for y.
Example using named columns
import plotly.express as px
iris = px.data.iris()
fig = px.scatter(iris, x="sepal_width", y="sepal_length")
fig.show()
What i want (bogus example)
import plotly.express as px
iris = px.data.iris()
fig = px.scatter(iris, x="index", y="sepal_length")
fig.show()
This obviously throws:
ValueError: Value of 'x' is not the name of a column in 'data_frame'. Expected one of ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', 'species_id'] but received: index
Ugly fix
import plotly.express as px
iris = px.data.iris().reset_index()
fig = px.scatter(iris, x="index", y="sepal_length")
fig.show()