学院教职工职称因子归一化去重并合并为单一列表
Got it, let's break down how to solve this problem—whether you're using a data processing library like pandas (great for larger datasets) or just plain Python for simpler lists, I've got you covered.
Using Python's Pandas (Recommended for Structured Data)
If your faculty data is in a dataframe (like from a CSV/Excel file), pandas makes this straightforward:
Import pandas and load your data
import pandas as pd # Replace this with your actual data loading code (e.g., pd.read_csv("faculty_data.csv")) sample_data = { "Name": ["Alice Smith", "Bob Jones", "Charlie Brown", "Diana Lee", "Eve Adams"], "Title": ["Professor", "Distinguished Professor", "Assistant Teaching Professor", "Instructor", "Professor"] } df = pd.DataFrame(sample_data)Standardize titles to merge categories
Create a mapping to reclassify "Distinguished Professor" as "Professor", then apply it to your title column:title_consolidation = { "Distinguished Professor": "Professor" # Add more key-value pairs here if you need to merge other titles later } df["Standardized_Title"] = df["Title"].replace(title_consolidation)Extract unique standardized titles
Useunique()to get distinct values, then convert to a list for readability:unique_standardized_titles = df["Standardized_Title"].unique().tolist() print(unique_standardized_titles)Output:
['Professor', 'Assistant Teaching Professor', 'Instructor']
Pure Python Approach (For Simple Lists)
If you're working with a basic list of titles instead of a dataframe, this method works perfectly:
# Your raw list of faculty titles (replace with your actual data) raw_titles = ["Professor", "Distinguished Professor", "Assistant Teaching Professor", "Instructor", "Professor"] # Define the consolidation rule title_mapping = {"Distinguished Professor": "Professor"} # Standardize each title standardized_titles = [title_mapping.get(title, title) for title in raw_titles] # Get unique values (convert to set first, then back to list) unique_titles = list(set(standardized_titles)) # Optional: sort the list alphabetically unique_titles.sort() print(unique_titles)
Output:
['Assistant Teaching Professor', 'Instructor', 'Professor']
Both methods will give you the unique, consolidated titles you need. Adjust the mapping dictionary if you ever need to merge additional title categories later!
内容的提问来源于stack exchange,提问作者Kuai

