Python Forum
TypeError: list indices must be integers or slices, not float - 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: TypeError: list indices must be integers or slices, not float (/thread-26024.html)



TypeError: list indices must be integers or slices, not float - hissonrr - Apr-18-2020

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()



RE: TypeError: list indices must be integers or slices, not float - deanhystad - Apr-18-2020

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?


RE: TypeError: list indices must be integers or slices, not float - hissonrr - Apr-19-2020

(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