Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating age from date/time format in python/pandas

Tags:

pandas

Looking for a way to calculate age from the following date/time format in python.

eg: 1956-07-01T00:00:00Z

I have written a code to do this by extracting the four characters of the string, convert it to an int and subtract it from 2017 but was looking to see if there is an efficient way to do it.

like image 806
Nivi Avatar asked Oct 01 '17 03:10

Nivi


People also ask

How do I get age from DateTime?

int age = (int) ((DateTime. Now - bday). TotalDays/365.242199);

How do I get the current age in Python?

You can get the current url by doing path_info = request. META. get('PATH_INFO') http_host = request.


1 Answers

Is this what you want ?

(pd.to_datetime('today').year-pd.to_datetime('1956-07-01').year)

Out[83]: 61
like image 156
BENY Avatar answered Oct 20 '22 06:10

BENY