I am trying to get the average value of Price
import pandas as pd
df = pd.read_csv('sample_data1.csv')
#file sample
Name,Price
Eedor,"¥1,680"
Avidlove,"¥11,761"
Fitment,
Vintage,$8.95 - $16.95
silhouette,$27.80 - $69.50
Silk,$50.02
I am trying to get the average value in the "Price" column, then if it is in Yen convert to USD I have written this small function which should do the job, I am not sure how can I apply it on the column
import re
#1¥ =0.0090$
def my_func(value):
if not value:
return None #remove row
elif "¥" in value:
try:
temp = re.search(r'(\d+\,*\.*\d*) - .(\d+\,*\.*\d*)',value).groups()
return (float(temp[0].replace(',',''))+float(temp[1].replace(',','')))*0.09/2
except:
return float(re.search(r'(\d+\,*\.*\d*)',value).groups()[0].replace(',',''))*0.009
else:
try:
temp = re.search(r'(\d+\,*\.*\d*) - .(\d+\,*\.*\d*)',value).groups()
return (temp[0]+temp[1])/2
except:
return float(re.search(r'(\d+\,*\.*\d*)',value).groups()[0].replace(',',''))
What I want is to replace the price column with the average value in $