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.