Line_chart order of lines are not right

I am creating a line chart to show frequency
and as you can see the “braço 1” is right next to “braço 10” and it should be “braço 2” and so on

def frequency(choices,allrewards):
  st.write("### Frequência de recompensas")
  df = pd.DataFrame(allrewards).T
  df.columns = [f"Braço {i+1}" for i in range(len(allrewards))]
  df.index.name = "Execução"
  st.line_chart(df)

#example of choices

[24, 12, 22, 23, 19]

#example of allRewards

[[3.123895227453449, 3.515965858835796, 4.171472032800911], [4.2779499849109595], [1.3887435377347015, 3.4967789928358304], [3.807072733441112], [3.728360638605822, 3.142179167264145, 5.329350022687842]]

That is how strings are sorted.

>>> l = [f"Braço {i+1}" for i in range(10)]
>>> l
['Braço 1', 'Braço 2', 'Braço 3', 'Braço 4', 'Braço 5', 'Braço 6', 'Braço 7', 'Braço 8', 'Braço 9', 'Braço 10']
>>> sorted(l)
['Braço 1', 'Braço 10', 'Braço 2', 'Braço 3', 'Braço 4', 'Braço 5', 'Braço 6', 'Braço 7', 'Braço 8', 'Braço 9']

How would I change it to sort like the first array? in the numeric way

I don’t think you can do that with st.line_chart. Probably you can use st.altair_chart but then I don’t know much about altair.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.