Skip to content
Advertisement

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:

last_name first_name birthday
Cawthorn David 1995-08-01

Advertisement

Answer

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())]
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement