Convert the date (start and stop) to a time interval so I can compare using Python -


hello working .csv file contains birth date , death date of presidents. problem trying solve year year presidents alive. assume this, have convert dates of birth , deaths of presidents time series , presidents alive, have have death dates changed present time. know can go doing using python , packages - pandas , numpy? here code have far:

also date in format: feb 22 1732 if president hasn't died death date blank

#!/usr/bin/python  #simple problem: find year presidents #were alive import pandas pd import numpy np #import presidents.csv , save dataframe  presidents = pd.read_csv('presidents.csv') #view first ten lines of dataframe  presidents.head(10) #change column names remove whitespace  presidents.columns = ['president','birth date','birth place','death date','location of death']  #save column names of dataframe list  columns_of_pres = list(presidents.columns) #create data frame contains name, birth , death date of president birth_and_deathbirth_and_death = presidents[['president','birth date','death date']] 

if goal solve year year presidents alive, should 1) year out of date field year = 'feb 22 1732'.split(' ')[-1] 2) each president make list of years in alive. aliveyears = range(birthyear,deathyear) 3) use collections.counter() count year find presidents.

something this:

from collections import counter yearcount = counter() p in presidents:     birthyear = ....split(' ')[-1]     deathyear = ....split(' ')[-1]     year in range(birthyear,deathyear):         yearcount.update({year}) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -