Tuesday, April 17, 2018

Pandas Dataframe example

import pandas as pd
import numpy as np
df = pd.read_csv('employees.csv',parse_dates=['Start Date','Last Login Time'])
df['Senior Management'] = df['Senior Management'].astype('bool')
df["Gender"]  = df['Gender'].astype("category")
df.info()

mask1 = df['Senior Management']
mask2 = df['Start Date']< '1990-01-01'

df [ mask1 | mask2]

mask1 = df['Gender'] == 'Male'
mask2 = df['Team'] == 'Marketing'

df[mask1 & mask2].head(3)

df[~df["Team"].duplicated()]

df.drop_duplicates(['Team'])