【发布时间】:2020-01-16 22:19:37
【问题描述】:
我为 ESPN 网站的团队编写了一个通用函数,其中包含两个元素 team_id 和 team_name 的数据框。 我想编写一个代码,它会根据给定的 team_id 和 team_name 生成一个自定义的 url。
Example : team_id = 2132 and team_name = Cincinnati Bearcats
下面是代码
def get_team_url(team_id, team_name):
import pandas as pd
df = pd.DataFrame(['team_id','team_name'])
df['url'] = 'http://www.espn.com/college-football/team/roster/_/?id=' + df.iloc[0]+ '&team_name=' +
df.iloc[1]
return df
当我为函数提供值时,我在 Jupiter 笔记本中遇到以下错误
当我在不同的 shell 中编写断言函数时:
assert team_url == 'https://www.espn.com/college-football/team/roster/_/id/2132/Cincinnati Bearcats'
然后我得到以下错误:
ValueError:DataFrame 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
【问题讨论】:
标签: python-3.x pandas dataframe jupyter-notebook data-science