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: index 0 is out of bounds for axis 0 with size 0 atomxkai 1 109 Feb-27-2021, 12:53 AM
Last Post: nealc
  [split] Getting Index Error - list index out of range krishna 2 203 Jan-09-2021, 08:29 AM
Last Post: buran
  Getting Index Error - list index out of range RahulSingh 2 1,816 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  pandas.read_sas with chunksize: IndexError list index out of range axelle 0 692 Jan-28-2020, 09:30 AM
Last Post: axelle
  IndexError: index out of bounds LeoGER 3 4,912 Sep-05-2019, 02:05 PM
Last Post: LeoGER
  How matplotlib automatically set x-axis and y-axis limits for bar graph ? ift38375 3 2,383 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 2,023 Feb-28-2019, 05:47 PM
Last Post: Larz60+
  Regarding index out of bounds error and implementing Loop error in backpropagation al geevaprasa 6 5,230 Apr-20-2018, 09:35 AM
Last Post: Larz60+
  Unable to understand reason for error IndexError: tuple index out of range rajat2504 4 49,141 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