I want to take the string 'APPLES_10_4' inside a dataframe and have it become 'APPLES'. The code I have come up with is below:
import pandas as pd
data = ['APPLES_10_4']
Name_Parameters = []
df = pd.DataFrame(data, columns = ['fruit'], index = ['count'])
    
def badletters(lastletter):
    badletters = ["1","2","3","4","5","6","7","8","9","_"]
    if lastletter in badletters:
        return True
    else:
        return False   
def stripe(variable):
    tempStrippedVariable = variable
    foundEndVariable = False
    while not foundEndVariable:
        lastletter = tempStrippedVariable [:-1]
        if badletters(lastletter):
            tempStrippedVariable = tempStrippedVariable [:-1]
        else:
            foundEndVariable = True
    strippedVariable = tempStrippedVariable
    return strippedVariable
for variable in df:
strippedVariable = stripe(str(variable))
prefixes = []
if strippedVariable not in prefixes:
    prefixes.append(strippedVariable)
print(df)
The output I am getting is the original dataframe with ['APPLES_10_4'] not the altered one that says ['APPLES'].
 
     
    