After the glorious work made by @adam.kubalica with scraping all the budgets, I’m trying to clean each string and converting them into float numbers.
This is the function I wrote which is working just fine when I test it with random strings but not with the dataframe
def budget_neat(df): budget = df['movie_budget'] if budget is not None: #splitting the budget with more than 1 value stripped = budget.strip() #need this if statement cause some '-' are differntly encoded if re.search('–', stripped): splitted = stripped.split('–') #converting values into float floated = [float(i) for i in splitted] #calculating the mean mean_value = sum(floated) / len(floated) return mean_value else: splitted = budget.split('-') floated = [float(i) for i in splitted] #calculating the mean mean_value = sum(floated) / len(floated) return mean_value else: return None
showing me this error:
AttributeError: ‘float’ object has no attribute ‘strip’
I don’t understand why. Could you please help?
I’ll leave the csv I created and part of my work on the jupyter notebook
fandango_2015.csv (12.7 KB)
fandango_cleaning.ipynb (98.5 KB)
Thanks for your kind help in advance
Click here to view the jupyter notebook file in a new tab