Hi, I'm kind of new to python and I have been trying to split a time column in order to convert it all into a single unit but my splitting function does not work.
mydata= pd.read_excel("myclock.xlsx",sheet_name="mytime",skiprows=0, index_col = [1])
Name ID Date Check In Check Out
Worker_one 00001 Friday, September 28, 2018 9:50:35 18:50:23
Worker_two 00002 Friday, September 28, 2018 10:43:03 19:54:34
Worker_tree 00003 Friday, September 28, 2018 9:37:45 18:38:01
Worker_four 00004 Friday, September 28, 2018 8:44:07 17:30:04
Worker_five 00005 Friday, September 28, 2018 8:30:54 17:30:30
Worker_six 00006 Friday, September 28, 2018 9:01:43 18:04:50
Worker_seven 00007 Friday, September 28, 2018 8:34:16 17:34:50
Worker_eight 00008 Friday, September 28, 2018 11:57:43 20:58:54
Worker_nine 00009 Friday, September 28, 2018 9:03:53 18:40:43
Worker_ten 00010 Friday, September 28, 2018 8:23:04 18:45:32
from datetime import time
:
try:
hours, minutes, seconds = time_str.split(":")
except ValueError:
return
return int(hours)*60+ int(minutes) + int(seconds)/60.0
Check_Out_Minutes = mydata['Check Out'].apply(time_to_minutes)
And it returns an attribute error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-d84e37515c72> in <module>()
----> 1 Check_Out_Minutes = mydata['Check Out'].apply(time_to_minutes)
C:\Program Files\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
2549 else:
2550 values = self.asobject
-> 2551 mapped = lib.map_infer(values, f, convert=convert_dtype)
2552
2553 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-5-c033186c9b10> in time_to_minutes(time_str)
1 def time_to_minutes(time_str):
2 try:
----> 3 hours, minutes, seconds = time_str.split(':')
4 except ValueError:
5 return
AttributeError: 'datetime.time' object has no attribute 'split'
mydata= pd.read_excel("myclock.xlsx",sheet_name="mytime",skiprows=0, index_col = [1])
Name ID Date Check In Check Out
Worker_one 00001 Friday, September 28, 2018 9:50:35 18:50:23
Worker_two 00002 Friday, September 28, 2018 10:43:03 19:54:34
Worker_tree 00003 Friday, September 28, 2018 9:37:45 18:38:01
Worker_four 00004 Friday, September 28, 2018 8:44:07 17:30:04
Worker_five 00005 Friday, September 28, 2018 8:30:54 17:30:30
Worker_six 00006 Friday, September 28, 2018 9:01:43 18:04:50
Worker_seven 00007 Friday, September 28, 2018 8:34:16 17:34:50
Worker_eight 00008 Friday, September 28, 2018 11:57:43 20:58:54
Worker_nine 00009 Friday, September 28, 2018 9:03:53 18:40:43
Worker_ten 00010 Friday, September 28, 2018 8:23:04 18:45:32
from datetime import time
:
try:
hours, minutes, seconds = time_str.split(":")
except ValueError:
return
return int(hours)*60+ int(minutes) + int(seconds)/60.0
Check_Out_Minutes = mydata['Check Out'].apply(time_to_minutes)
And it returns an attribute error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-d84e37515c72> in <module>()
----> 1 Check_Out_Minutes = mydata['Check Out'].apply(time_to_minutes)
C:\Program Files\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
2549 else:
2550 values = self.asobject
-> 2551 mapped = lib.map_infer(values, f, convert=convert_dtype)
2552
2553 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-5-c033186c9b10> in time_to_minutes(time_str)
1 def time_to_minutes(time_str):
2 try:
----> 3 hours, minutes, seconds = time_str.split(':')
4 except ValueError:
5 return
AttributeError: 'datetime.time' object has no attribute 'split'