Created
January 5, 2022 23:27
-
-
Save khuyentran1401/4d73d9a8cafcfce95e3b3ccbd8fe951f to your computer and use it in GitHub Desktop.
This file contains 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
def str_to_interval(text: str): | |
if isinstance(text, str): | |
years = text.split()[0].split("-") | |
if len(years) == 2: | |
return pd.Interval(int(years[0]), int(years[1])) | |
else: | |
return pd.Interval(int(years[0]), float("inf")) | |
return text | |
# Convert string to pandas.Interval | |
normal_salary.YearsCoding = normal_salary.YearsCoding.apply(str_to_interval) | |
# Sort by years | |
years_sorted = normal_salary.dropna( | |
subset=["ConvertedSalary", "YearsCoding"] | |
).sort_values(by="YearsCoding") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment