Reputation: 31
How can i use pandas datetools in python because it removed from newer version
def convert_time(s):
h, m, s = map(int, s.split(':'))
return pd.datetools.timedelta(hours=h, minutes=m, seconds=s)
data = pd.read_csv('marathon-data.csv',converters={'split':convert_time, 'final':convert_time})
data.head()
Upvotes: 2
Views: 1220
Reputation: 2153
Since pd.datetools.timedelta
is deprecated, using datetime.timedelta
is a possible workaround.
Try this updated code snippet:
import datetime
def convert_time(s):
h, m, s = map(int, s.split(':'))
return datetime.timedelta(hours=h, minutes=m, seconds=s)
data = pd.read_csv('marathon-data.csv',
converters={'split':convert_time, 'final':convert_time})
data.head()
Upvotes: 0
Reputation: 249394
You can replace your convert_time()
function with pd.to_timedelta()
. It is built in to Pandas and understands HH:MM:SS and similar formats.
Upvotes: 2