Here is my csv file in case you need it
我试着把每一支大联盟球队的季后赛出场记录下来,但是"DataFrame" has not attribute to "str"
总是出现。这是我的密码:
record_dict = {}
file=open("playoff_teams.csv", mode="r")
for line in file.readlines():
split_line = line.split()
record_dict[split_line[0]]=split_line[1:]
df_playoffs = pd.DataFrame.from_dict(record_dict, orient='index' )
list(sorted(set(df_pitching.team))) == list(sorted(set(df_batting.team))) == list(sorted(set(df_playoffs.index)))
df_all = df_pitching.merge(df_batting, on=['year','team'],
how='left', suffixes=('_pitching', '_batting'))
playoff_appearance = []
for i in range(1969, 2019):
df = df_all[df_all.year == i]
for team in df.team:
df_plyoff = df_playoffs[df_playoffs.index == team]
if df_plyoff.str.contains(str(i))[0]:
playoff_appearance.append(1)
else:
playoff_appearance.append(0)
world_series = []
for i in range(1969, 2019):
df = df_all[df_all.year == i]
for team in df.team:
df_ws = df_playoffs[df_playoffs.index == team]
if df_ws.world_series.str.contains(str(i))[0]:
world_series.append(1)
else:
world_series.append(0)
这是我的错误信息:
Traceback (most recent call last):
File "/Users/hannahbeegle/Desktop/Baseball.py", line 148, in <module>
if df_plyoff.str.contains(str(i))[0]:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 5067, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'str'
在尝试访问该单元格的值之前,必须先获取相应的列。引起问题的行应改为:
我假设包含年份的列没有指定名称,因此默认为
0
。如果有,请告诉我。你知道吗相关问题 更多 >
编程相关推荐