Python Forum

Full Version: IndexError: index 0 is out of bounds for axis 0 with size 0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good day fellow coders,

I am a little stuck with index error issue. Below is the description:

Table name: Sub
ID, Pred
2014_1107_1110, 0.5
2014_1107_1112, 0.5
2014_1107_1113, 0.5
2014_1107_1124, 0.5

Season
Season, Seed, TeamID
1998, W01, 3330
1998, W02, 3163
1998, W03, 3112
1998, W04, 3301


Method to simplfy the dataset

def seed_to_int(seed):
    s_int = int(seed[1:3])
    return s_int
df_seeds['seed_int'] = df_seeds.Seed.apply(seed_to_int)
df_seeds.drop(labels = ['Seed'], inplace = True, axis = 1)
df_seeds.head()


[b]Output from simplification method

Season TeamID seed_int
0 1998 3330 1
1 1998 3163 2
2 1998 3112 3
3 1998 3301 4
4 1998 3272 5


Pandas encaps SeedsTable
df_seeds = pd.read_csv(data_directory + '/Seeds.csv')
output
Season Seed TeamID
0 1998 W01 3330
1 1998 W02 3163
2 1998 W03 3112
3 1998 W04 3301
4 1998 W05 3272

Code that generates index Error

X_test = np.zeros(shape = (n_test_games, 1))

for ii, row in df_sample_sub.iterrows():
    year, t1, t2 = get_year_t1_t2(row.ID)
    t1_seed = df_seeds[(df_seeds.TeamID == t1) & (df_seeds.Season == year)].seed_int.values[0]
    t2_seed = df_seeds[(df_seeds.TeamID == t2) & (df_seeds.Season == year)].seed_int.values[0]
    diff_seed = t1_seed - t2_seed
    X_test[ii,0] = diff_seed
Actual index Error output
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-37-0215f157ee60> in <module>
      3 for ii, row in df_sample_sub.iterrows():
      4     year, t1, t2 = get_year_t1_t2(row.ID)
----> 5     t1_seed = df_seeds[(df_seeds.TeamID == t1) & (df_seeds.Season == year)].seed_int.values[0]
      6     t2_seed = df_seeds[(df_seeds.TeamID == t2) & (df_seeds.Season == year)].seed_int.values[0]
      7     diff_seed = t1_seed - t2_seed

IndexError: index 0 is out of bounds for axis 0 with size 0
Please can anyone proffer a solution to this?