Python Forum
TypeError: list indices must be integers or slices, not float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: list indices must be integers or slices, not float
#1
I'm very very new to python, any idea what I am doing wrong here?

#Now we label and color our facies
# 1=Mudstone_Org_Si  2=Mudstone_Org   3=Mudstone_ORG_Cal 
# 4=Mudstone_Cal_Si 5=Limestone_Arg_Dol 6=Limestone_Arg
facies_colors = ['#A09D92','#8E7308','#0B0901','#F5D451',
       '#EE44BB','#44BBEE']

facies_labels = ['MSOrgSi', 'MSOrg', 'MSOrgCal', 'MSCalSi', 'LSArgDol',
                 'LSArg']
#facies_color_map is a dictionary that maps facies labels
#to their respective colors
facies_color_map = {}
for ind, label in enumerate(facies_labels):
    facies_color_map[label] = facies_colors[ind]

def label_facies(row, labels):
    return labels[ row['Facies'] -1]
    
training_data.loc[:,'FaciesLabels'] = training_data.apply(lambda row: label_facies(row, facies_labels), axis=1)
training_data.describe()
Reply
#2
What is the error and what line is generating the error? What is row? What is training_data? What dos training_data.apply do? What argument does it expect?
Reply
#3
(Apr-18-2020, 11:13 PM)deanhystad Wrote: What is the error and what line is generating the error? What is row? What is training_data? What dos training_data.apply do? What argument does it expect?

here is the full error... and the training data is just an excel workbook with some numbers in it.

TypeError: ('list indices must be integers or slices, not float', 'occurred at index 4489')

here is the full script thus far...

%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from mpl_toolkits.axes_grid1 import make_axes_locatable

from pandas import set_option
set_option("display.max_rows", 10)
pd.options.mode.chained_assignment = None

training_data = pd.read_excel("../input/testdata/test.xlsx",sheet_name='RH Facies Lab Data')
training_data

# To evaluate the accuracy of the classifier,
# we will remove one well from the training set so that we can compare 
# the predicted and actual facies labels.
blind = training_data[training_data['Well Name'] == 'well 2']
training_data = training_data[training_data['Well Name'] != 'well 2']
blind

# Let's clean up this dataset. The 'Well Name' column 
# can be turned into a categorical data type.
training_data['Well Name'] = training_data['Well Name'].astype('category')
training_data['Well Name'].unique()

#Now we label and color our facies
# 1=Mudstone_Org_Si  2=Mudstone_Org   3=Mudstone_ORG_Cal 
# 4=Mudstone_Cal_Si 5=Limestone_Arg_Dol 6=Limestone_Arg
facies_colors = ['#A09D92','#8E7308','#0B0901','#F5D451',
       '#EE44BB','#44BBEE']

facies_labels = ['MSOrgSi', 'MSOrg', 'MSOrgCal', 'MSCalSi', 'LSArgDol',
                 'LSArg']
#facies_color_map is a dictionary that maps facies labels
#to their respective colors
facies_color_map = {}
for ind, label in enumerate(facies_labels):
    facies_color_map[label] = facies_colors[ind]

def label_facies(row, labels):
    return labels[ row['Facies'] -1]
    
training_data.loc[:,'FaciesLabels'] = training_data.apply(lambda row: label_facies(row, facies_labels), axis=1)
training_data.describe()

nvm im just a dumbass and had null values in my dataset
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tuple indices must be integers or slices, not str cybertooth 16 11,075 Nov-02-2023, 01:20 PM
Last Post: brewer32
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,091 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,181 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,256 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,180 Mar-24-2023, 08:34 AM
Last Post: fullytotal
Question How to append integers from file to list? Milan 8 1,358 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  convert string to float in list jacklee26 6 1,813 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 1,931 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable #1 isdito2001 1 1,044 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  Error "list indices must be integers or slices, not str" dee 2 1,393 Dec-30-2022, 05:38 PM
Last Post: dee

Forum Jump:

User Panel Messages

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