python - 使用 print (", ".join(my_array)) 提取单个字符串并将其添加到 Streamlit Markdown 中。我没有得到字符串,而是没有得到任何东西

标签 python pandas markdown nonetype streamlit

我正在使用 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)

之前我并没有考虑到我的球队以最大优势获胜的球队可能不止一支。然而,事实证明,存在 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'

关于python - 使用 print (", ".join(my_array)) 提取单个字符串并将其添加到 Streamlit Markdown 中。我没有得到字符串,而是没有得到任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62250996/

相关文章:

markdown - Atom Markdown 警告

python - 使用 __init__() 中的请求数据更改 django 表单中输入的内容

python - 如何在Python中查找字符串中所有出现的子字符串

python - 使用 pandas.date_range() 生成多个日期时间,每周两个日期

Python Pandas 输出四舍五入的 DataFrame 到字典

python - 使用 Pandas 计算 12 月 - 1 月 - 2 月平均值

python - 新数组的总大小必须不变

python - 在 python 2.6 脚本中执行从终端获取参数的终端命令

java - 如何添加和使用 MarkdownView android 库

r - 如何在 RStudio Markdown 中编译 pdf?