Spaces:
Sleeping
Sleeping
Update app.py
Browse files5 unmodified lines6789910111213141213141516171819202122232425262728293031323316171819203435363738394041424344454647484950515253222354555657585 unmodified lines64656667686970717273745 unmodified linesimport re
def clean_salary(salary_str): """Extract and clean salary information, including ranges.""" """Extract and clean salary information, including ranges and hourly rates.""" if pd.isna(salary_str): return 0
# Handle ranges like "150000-200000" range_match = re.match(r'(\d+)[^\d]+(\d+)', str(salary_str)) salary_str = str(salary_str).lower().replace(',', '') # Convert hourly rate to annual salary (assuming 40 hours/week, 52 weeks/year) HOURS_PER_YEAR = 40 * 52 # 2080 hours per year # Handle hourly rates with ranges (e.g., "50-54 an hour" or "$50-$54/hr") hourly_range_match = re.search(r'(\d+\.?\d*)\s*[-to]+\s*(\d+\.?\d*)\s*(?:an hour|per hour|\/hour|\/hr|\$?\/h|\$?ph|hr)', salary_str) if hourly_range_match: low, high = map(float, hourly_range_match.groups()) avg_hourly = (low + high) / 2 return int(avg_hourly * HOURS_PER_YEAR) # Handle single hourly rate (e.g., "50 an hour" or "$50/hr") hourly_match = re.search(r'(\d+\.?\d*)\s*(?:an hour|per hour|\/hour|\/hr|\$?\/h|\$?ph|hr)', salary_str) if hourly_match: hourly_rate = float(hourly_match.group(1)) return int(hourly_rate * HOURS_PER_YEAR) # Handle ranges for annual salary (e.g., "150000-200000" or "150k-200k") range_match = re.search(r'(\d+\.?\d*)\s*k?\s*[-to]+\s*(\d+\.?\d*)\s*k?', salary_str) if range_match: low, high = map(int, range_match.groups()) return (low + high) // 2 # Return average of range
# Extract single salary value numbers = re.findall(r'\d+', str(salary_str)) low, high = map(float, range_match.groups()) # Convert if 'k' is in the string if 'k' in salary_str: low *= 1000 high *= 1000 return int((low + high) // 2) # Handle single values with 'k' (e.g., "150k" or "150K") k_match = re.search(r'(\d+\.?\d*)\s*k', salary_str) if k_match: return int(float(k_match.group(1)) * 1000) # Extract plain numbers numbers = re.findall(r'\d+\.?\d*', salary_str) if numbers: # Take the first number found salary = float(numbers[0]) # If the number is small (likely in thousands), multiply by 1000 if salary < 1000: salary *= 1000 return int(numbers[0])
return int(salary) return 0
def load_and_preprocess_data(url):5 unmodified lines
# Clean salary column df['clean_salary'] = df['Salary'].apply(clean_salary) # Add debug print for salary cleaning st.write("Sample of cleaned salaries:") sample_df = df[['Salary', 'clean_salary']].head() st.write(sample_df)
# Combine title and description for better clustering df['combined_text'] = df['Title'].str.lower() + ' ' + df['Description'].str.lower()app.py+48-11