我想根據計算兩個事件之間時間的條件語句在熊貓中創建一列。我能工作了一天計算,但是當插入我的條件語句:熊貓日期條件計算
def defect_age(df):
if df['Status'] == 'R':
return (pd.to_datetime(df['resolved_on'], errors='coerce') - pd.to_datetime(df['submitted_on']))/np.timedelta64(1, 'D')
else:
return 'null'
,後來被列名爲:
group_df['Age'] = group_df.apply(defect_age(group_df), axis=0)
我收到以下錯誤:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我試圖基於我提問HERE的問題...但我沒有太大的成功。任何幫助表示讚賞!
太棒了!謝謝。你的答案正是我試圖弄清楚的。我有更多的狀態,我現在要添加:) – anshanno