Reputation: 1190
I have the following code which gives the following output:
print(df1['Diff'].mean())
outputs:
10 days 16:13:29.467455
But since i just want the days value and not the time, i have done this:
print(datetime.strptime(df1['Diff'].mean(), format ='%d')
but i am getting the following error:
^
SyntaxError: unexpected EOF while parsing
Why am i getting this error?
Upvotes: 0
Views: 35
Reputation: 476
I think the instance of df1['Diff'].mean()
is str
and datetime.strptime()
can be use only in datetime
methods. So to only get date you have to take slice of df1['Diff'].mean()
like df1['Diff'].mean()[:-14]
Which is in your case.
Upvotes: 1
Reputation: 8077
date
, time
, and datetime
objectsYou should be using strftime
to format the time, not to parse the time (as in strptime
).
print(obj.strftime('%d'))
strptime
expects a string to be passed in (and you were passing in a datetime
object), whereas strftime
formats an existing datetime
object.
timedelta
objectsprint(obj.days)
This gets the days counterpart you're looking for.
Upvotes: 1