Python Forum
IndexError: index 0 is out of bounds for axis 0 with size 0
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexError: index 0 is out of bounds for axis 0 with size 0
#1
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: invalid index to scalar variable. jyotib2610 3 3,081 Mar-10-2022, 09:55 AM
Last Post: jyotib2610
  IndexError: index 0 is out of bounds for axis 0 with size 0 atomxkai 2 5,455 Mar-03-2021, 08:26 AM
Last Post: atomxkai
  [split] Getting Index Error - list index out of range krishna 2 2,605 Jan-09-2021, 08:29 AM
Last Post: buran
  Getting Index Error - list index out of range RahulSingh 2 6,145 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  pandas.read_sas with chunksize: IndexError list index out of range axelle 0 2,578 Jan-28-2020, 09:30 AM
Last Post: axelle
  IndexError: index out of bounds LeoGER 3 10,644 Sep-05-2019, 02:05 PM
Last Post: LeoGER
  How matplotlib automatically set x-axis and y-axis limits for bar graph ? ift38375 3 5,526 Jul-04-2019, 08:23 AM
Last Post: scidam
  Can you help me with this error? IndexError: invalid index of a 0-dim tensor. DerBerliner 1 4,172 Feb-28-2019, 05:47 PM
Last Post: Larz60+
  Regarding index out of bounds error and implementing Loop error in backpropagation al geevaprasa 6 8,561 Apr-20-2018, 09:35 AM
Last Post: Larz60+
  Unable to understand reason for error IndexError: tuple index out of range rajat2504 4 54,122 Dec-09-2016, 11:04 AM
Last Post: Kebap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020