Created
November 14, 2024 19:22
-
-
Save davidrajm/c2d0556d305c814af84921a4680edbe3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import random | |
# Define departments and create a sample hierarchy | |
departments = [ | |
'Executive', 'Finance', 'HR', 'IT', 'Marketing', 'Sales', 'Engineering', | |
'Customer Service', 'Product Development', 'Legal', 'Operations', 'R&D' | |
] | |
# Generate random hierarchy relationships | |
data = [] | |
for i in range(1, len(departments)): | |
# Choose a random parent department from earlier in the list for hierarchy structure | |
parent_dept = departments[random.randint(0, i - 1)] | |
child_dept = departments[i] | |
data.append({'Parent_Department': parent_dept, 'Sub_Department': child_dept}) | |
# Convert to a DataFrame and save as CSV | |
df = pd.DataFrame(data) | |
df.to_csv('department_hierarchy.csv', index=False) | |
print("Department hierarchy dataset created and saved as 'department_hierarchy.csv'.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment