i'm trying to convert a column of prices in a dataframe into float and then calculate the mean of the first 5 rows. first i did it succussefully in this way :
import pandas as pd
import numpy as np
paris_listing = pd.read_csv("C:../.../.../paris_airbnb.csv")
stripped_commas = paris_listing["price"].str.replace(",", "")
stripped_dollars = stripped_commas.str.replace("$", "")
paris_listing["price"] = stripped_dollars.astype("float")
mean_price = paris_listing.iloc[0:5]["price"].mean()
print (mean_price)
but i tried to make a function and apply it on the dataframe and it didn't work
def conversion_price(price_conv):
price_conv = price_conv.str.replace(",", "")
price_conv = price_conv.str.replace("$", "")
price_conv = price_conv.astype("float")
price_mean = price_conv.iloc[0:5].mean()
paris_listing["converted_price"] = paris_listing["price"].apply(conversion_price)
pandasquestion, and has nothing to do withmachine-learning(tags edited).return price_conv