Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to print first name, last name and birthday in python?

I’m trying to print first name, last name and birthday, so how i could do it?

Here’s my code:

import pandas as pd
import numpy as np
from datetime import datetime, date

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)
df = pd.read_csv("legislators-current.csv")
df.shape

oldest = df['birthday'].min()
print(oldest) 
  

Output should be like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

last_name first_name birthday
Cawthorn David 1995-08-01

>Solution :

First add parse_dates to read_csv for datetimes:

df = pd.read_csv("legislators-current.csv", parse_dates=['birthday'])

Then if need filter by minimal birthday and columns in list use DataFrame.loc:

df.loc[df['birthday'].eq(df['birthday'].min()), ['last_name','first_name','birthday']]

For all columns use boolean indexing:

df[df['birthday'].eq(df['birthday'].min())]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading