Search code examples
pythonpandasmarkdownnonetypestreamlit

Using print(", ".join(my_array)) to extract individual strings and adding it to streamlit markdown. Instead of getting the string, I am getting NONE


I am using Streamlit to showcase some work that I have been doing on some data. So I have a dataframe named total_home_wins that contains the scores of the matches won by my team at home in the league. I am trying to find out the largest win won by my team. Kindly note that:

  • gd: Goal Difference
  • FTHG: Fulltime Home Goals

The following is my code to determine that:

biggest_gd_home = total_home_wins.loc[total_home_wins["gd"] == total_home_wins["gd"].max()]
biggest_win_home = biggest_gd_home.loc[biggest_gd_home["FTHG"] == biggest_gd_home["FTHG"].max()]
biggest_win_home_opponent = biggest_win_home.loc[:, "AwayTeam"].values[0]

And I was printing it on a page like so:

f'### Biggest victory at home against {biggest_win_home_opponent}'
st.write(biggest_win_home)

Previously I was not considering the fact that there could be more than one team with which my team won by the biggest margin. However, it turns out that there is a case where the both the gd and FTHG are exactly the same. No, problem - changed the code to the following:

biggest_win_home_opponent = list(biggest_win_home.loc[:, "AwayTeam"].values)

So now I have biggest_win_home_opponent as an array. If I leave the code as it is, it prints:

Biggest victory at home against ['Team X', 'Team Y']

I wanted it to appear without the brackets and the quotation marks, so I did the following:

'Biggest victory at home against' + print(", ".join(biggest_win_home_opponent))

This results in NONE instead of the team names. I tried replacing the + with , but to the same effect.

What am I doing wrong? Thanks in advance for your help!


Solution

  • You could try modifying your f string code after having defined the list as you did:

    f'### Biggest victory at home against {", ".join(biggest_win_home_opponent)}'
    st.write(biggest_win_home)
    

    As a prove of concept:

    biggest_win_home_opponent = ['Team X', 'Team Y']
    f'### Biggest victory at home against {", ".join(biggest_win_home_opponent)}'
    

    Outputs this:

    '### Biggest victory at home against Team X, Team Y'