我又问了一个新手问题。从Excel获得以下数据框,我发现错误,是否有人能告诉我我做错了什么,谢谢:
编辑: 以下是Excel中的列
+----+--------+------+----+----+---+----+-----+----+-----+----+-------+-------+----------+--------+-----------+--------+-----+--------+------------+------+----------+-------+------------+-------+---------+-----+-----+-----+-----+------+----+-----+------+-----------+----------+----------+---------+
| Rk | Player | From | To | Tm | G | GS | Yrs | PB | AP1 | AV | GS/Yr | AV/Yr | QB_score | Height | Height-in | Weight | BMI | School | BCS School | 40YD | Vertical | Bench | Broad Jump | 3cone | Shuttle | Cmp | Att | Pct | Yds | AY/A | TD | Int | Rate | Rush_Att | Rush_Yds | Rush_Avg | Rush_TD |
+----+--------+------+----+----+---+----+-----+----+-----+----+-------+-------+----------+--------+-----------+--------+-----+--------+------------+------+----------+-------+------------+-------+---------+-----+-----+-----+-----+------+----+-----+------+-----------+----------+----------+---------+
KeyError: "['Rush_Att'] not in index"
df = pd.read_excel('sportsref-qbdata-raw-v2.xlsx', header=1)
cols_to_keep = ['Player', 'QB_score', 'Height-in', 'Weight', 'BMI', 'BCS School', 'Cmp', 'Att', 'Pct', 'Yds', 'AY/A', 'TD', 'Int', 'Rate', 'Rush_Att', 'Rush_Yds', 'Rush_Avg', 'Rush_TD']
df = df[cols_to_keep]
您不必使用
header = 1
,因为您只有一行标头、删除标头参数或使用header = 0
或header = [0]
相关问题 更多 >
编程相关推荐