1
我不是大熊貓大熊貓具有功能的地圖字符串列
很熟悉所以我有一個問題,就是以下幾點:
我想基於字符串列得到的天數
Period
3 days
5 weeks
1 year
我想這列轉換爲整數,它是天的這樣的數字:
Days
3
35
365
我做了如下:
def toDays(dt):
if 'year' in dt:
for s in dt:
if s.isdigit():
return int(s)*360
elif 'month' in dt:
for s in dt:
if s.isdigit():
return int(s)*30
elif 'week' in dt:
for s in dt:
if s.isdigit():
return int(s)*7
if 'day' in dt:
for s in dt:
if s.isdigit():
return int(s)
train_file["Days"]=train_file["Periods"].map(toDays)
,但沒有工作,我會爲了這個函數映射到數據幀