Q: Plotting multiple line plots based on multi level index pandas dataframe the data frame looks like this: 
I am trying to plot the different columns as lines and keep the CES survey name as a the x axis or if there is a way to reshape the data where i can see the sentiment trend based on the survey name

*

*approaches tried I tried to use the facet_cols options in plotly express to create subplots based on years but it didn't show a neat trend line.


A: *

*have simulated your data using a multi index and random data

*simple to plot dimensions you state with Plotly Express just reset_index() first

df = pd.DataFrame(
    index=pd.MultiIndex.from_product(
        [
            range(2019, 2022),
            [
                "Calculations",
                "Dashboard Creation",
                "Margin Rules",
                "Quick Report",
                "Report Studio",
                "Schedule Report",
                "Smart Connector",
                "Widget Creation",
            ],
        ],
        names=["Year", "CES Survey Name"],
    )
).pipe(
    lambda d: d.assign(
        **{
            c: np.random.randint(0, 4, len(d))
            for c in ["negative", "neutral", "positive"]
        }
    )
)

px.line(
    df.reset_index(),
    x="CES Survey Name",
    y=["negative", "neutral", "positive"],
    color="Year",
).update_layout(xaxis={"type": "category"})


