def convertRate(row):
if pd.isnull(row):
return
elif ':' in str(row):
rows = row.split(':')
return - float(rows[])/float(rows[])
else:
return float(row)
#以上是要對每個資料進行的操作
def processData(df):
df['discount_rate'] = df['Discount_rate'].apply(convertRate)
#對‘Discount_rate’數組中的每一個資料進行convertRate函數的操作,傳回的也是一列數組。
ps:在python3中apply不能直接調用