IndexError: index 0 is out of bounds for axis 0 with size 0 error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: IndexError: index 0 is out of bounds for axis 0 with size 0 error (/thread-26220.html) |
IndexError: index 0 is out of bounds for axis 0 with size 0 error - tmhsa - Apr-24-2020 Good day fellow coders, I am a little stuck with an 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_seedActual 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 0As you can see, the prolem is pointing to this line: t1_seed = df_seeds[(df_seeds.TeamID == t1) & (df_seeds.Season == year)].seed_int.values[0]Please can anyone proffer a solution to this? RE: IndexError: index 0 is out of bounds for axis 0 with size 0 error - Jeff900 - Apr-24-2020 Can you add the traceback? RE: IndexError: index 0 is out of bounds for axis 0 with size 0 error - tmhsa - Apr-24-2020 (Apr-24-2020, 01:40 PM)Jeff900 Wrote: Can you add the traceback? I have never heard of a traceback with IndexError???? Are you sure this applies to this case? RE: IndexError: index 0 is out of bounds for axis 0 with size 0 error - Jeff900 - Apr-24-2020 A traceback is what you get as response when an error occurred. Like this: It gives a bit more info then just the error.
RE: IndexError: index 0 is out of bounds for axis 0 with size 0 error - tmhsa - Apr-24-2020 (Apr-24-2020, 02:52 PM)Jeff900 Wrote: A traceback is what you get as response when an error occurred. Like this: Like I said Jeff, your suggestion dosen't apply here. The only available traceback is: ----> 5 t1_seed = df_seeds[(df_seeds.TeamID == t1) & (df_seeds.Season == year)].seed_int.values[0]and the following: 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 RE: IndexError: index 0 is out of bounds for axis 0 with size 0 error - tmhsa - Apr-25-2020 I later figured this out myself..most of these issues just require persistence and hard work. |