Why cant I get ordered theese data?


I get this result

and this is the code

@app.callback(Output('linegraph001b', 'figure'), [Input('dropdown_line_chart12', 'value')], [Input('dropdown_line_chart22', 'value')],Input('paquito','data'),prevent_initial_call=True,suppress_callback_exceptions=True)#,[Input("intermediate-value",'data'),])
def filter_heatmap(drop1,drop2,data):#
    if data:
        dff=pd.read_json(data,typ='frame',precise_float=True, orient='table')
        dff.replace("-", np.nan, inplace=True)


        dff2_[drop1] = dff2_[drop1].sort_values()
        dff2_ = dff2_.dropna(subset=[drop1])

        dff2_ = dff2_.dropna(subset=[drop2])

        figure = px.line(dff2_,x=dff2_[drop1],y=dff2_[drop2])
        figure.update_layout(transition_duration=500,template = 'plotly_dark')
        return figure
        raise PreventUpdate

What can I do to fix this and get a correct order?

I don’t think it is Dash problem but pandas. I think you should change dff2_[drop1] = dff2_[drop1].sort_values() to dff2_ = dff2_.sort_values(by='drop1')

For example:

import pandas as pd

df = pd.DataFrame({'Name': ['A', 'B', 'C', 'D', 'E'], 
                   'drop1': [1, 3, 2, 4, 5],
                   'drop2': [9,8,6,7,10]})

If used df['drop1'] = df['drop1'].sort_values(), dataframe will look like below:
Screenshot 2023-12-18 103856

If used df = df.sort_values(by='drop1'), dataframe will look like below:
Screenshot 2023-12-18 104149