This question already has an answer here:
Here is the DataFrame column and its datatype
df['Hours'].head()
OutPut:
0 00:00:00
1 00:00:00
2 11:38:00
3 08:40:00
Name: Hours, dtype: timedelta64[ns]
I want to conditionally form anaother column from it, such that it will look like.
Hours Test
00:00:00 N/A
00:00:00 N/A
11:38:00 02:38:00
08:40:00 Under Worked
Where ,
if df['Hours'] == '00:00:00':
df[Test] = 'N/A'
elif (df['Hours'].dt.total_seconds()//3600) < 9:
df['Test'] = 'Under Worked'
else:
df['Test'] = (df['Hours'].dt.total_seconds()//3600)-9
But it gives me error
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
How can it be solved?
Aucun commentaire:
Enregistrer un commentaire