我正在使用 Streamlit 来展示我在某些数据上所做的一些工作。因此,我有一个名为 total_home_wins
的数据框,其中包含我的球队在联赛主场赢得的比赛的得分。我试图找出我的球队赢得的最大胜利。请注意:
gd
:净胜球FTHG
:全场主场进球
以下是我的代码来确定:
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)
之前我并没有考虑到我的球队以最大优势获胜的球队可能不止一支。然而,事实证明,存在 gd
和 FTHG
完全相同的情况。不,问题 - 将代码更改为以下内容:
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'
关于python - 使用 print (", ".join(my_array)) 提取单个字符串并将其添加到 Streamlit Markdown 中。我没有得到字符串,而是没有得到任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62250996/