使用 print(", ".join(my_array)) 提取单个字符串并将其添加到 streamlit markdown。我得到的不是字符串,而是 NONE

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

我正在使用 Streamlit 来展示我在一些数据上所做的一些工作。所以我有一个名为 total_home_wins 的数据框,其中包含我的球队在联赛主场获胜的比赛得分。我试图找出我的团队赢得的最大胜利。请注意:

以下是我确定的代码:

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]

我把它打印在这样的页面上:

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

以前我没有考虑到我的团队可能有多个团队以最大的优势获胜。但是,事实证明存在 gdFTHG 完全相同的情况。不,问题 - 将代码更改为以下内容:

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

所以现在我有 biggest_win_home_opponent 作为数组。如果我按原样保留代码,它会打印:

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

我希望它不带括号和引号出现,所以我执行了以下操作:

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

这导致 NONE 而不是团队名称。我尝试用 , 替换 + 但效果相同。

我做错了什么?预先感谢您的帮助!

您可以在定义列表后尝试修改您的 f 字符串代码:

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

作为概念证明:

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

输出这个:

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