import pandas as pd
import numpy as np
# Generate a random DataFrame
data = {
'Employee ID': np.random.randint(1000, 9999, size=10),
'Full Name': ['Employee ' + str(i) for i in range(1, 11)],
'Job Title': np.random.choice(['Manager', 'Developer', 'Analyst', 'HR'], size=10),
'Department': np.random.choice(['IT', 'HR', 'Finance', 'Marketing'], size=10),
'Business Unit': np.random.choice(['Unit A', 'Unit B', 'Unit C'], size=10),
'Gender': np.random.choice(['Male', 'Female'], size=10),
'Ethnicity': np.random.choice(['Ethnicity 1', 'Ethnicity 2', 'Ethnicity 3'], size=10),
'Age': np.random.randint(20, 60, size=10),
'Hire Date': pd.date_range('2010-01-01', periods=10, freq='Y'),
'Annual Salary': np.random.randint(30000, 100000, size=10),
'Bonus %': np.random.uniform(5, 20, size=10),
'Country': np.random.choice(['USA', 'Canada', 'UK'], size=10),
'City': np.random.choice(['New York', 'Toronto', 'London'], size=10),
'Exit Date': pd.to_datetime(np.random.choice([None, '2021-12-31'], size=10))
}
df = pd.DataFrame(data)
# Query to calculate the median age of employees who left the company
median_age = df[df['Exit Date'].notnull()]['Age'].median()
print(median_age)
print(df[["Age", "Exit Date"]])
aW1wb3J0IHBhbmRhcyBhcyBwZAppbXBvcnQgbnVtcHkgYXMgbnAKCiMgR2VuZXJhdGUgYSByYW5kb20gRGF0YUZyYW1lCmRhdGEgPSB7CiAgICAnRW1wbG95ZWUgSUQnOiBucC5yYW5kb20ucmFuZGludCgxMDAwLCA5OTk5LCBzaXplPTEwKSwKICAgICdGdWxsIE5hbWUnOiBbJ0VtcGxveWVlICcgKyBzdHIoaSkgZm9yIGkgaW4gcmFuZ2UoMSwgMTEpXSwKICAgICdKb2IgVGl0bGUnOiBucC5yYW5kb20uY2hvaWNlKFsnTWFuYWdlcicsICdEZXZlbG9wZXInLCAnQW5hbHlzdCcsICdIUiddLCBzaXplPTEwKSwKICAgICdEZXBhcnRtZW50JzogbnAucmFuZG9tLmNob2ljZShbJ0lUJywgJ0hSJywgJ0ZpbmFuY2UnLCAnTW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