# -*- coding: utf-8 -*-
"""
Created on Mon Oct  5 11:44:28 2020

@author: jpark
"""

import pandas as pd

df = pd.read_csv('glassdoor_jobs.csv')

#salary parsing 

df['hourly'] = df['Salary Estimate'].apply(lambda x: 1 if 'per hour' in x.lower() else 0)
df['employer_provided'] = df['Salary Estimate'].apply(lambda x: 1 if 'employer provided salary:' in x.lower() else 0)

df = df[df['Salary Estimate'] != '-1']
salary = df['Salary Estimate'].apply(lambda x: x.split('(')[0]) #taking out (Glassdoor est.) in the Salary Estimate column
minus_Kd = salary.apply(lambda x: x.replace('K', '').replace('$','')) #taking out dollar signs and K

min_hr = minus_Kd.apply(lambda x: x.lower().replace('per hour','').replace('employer provided salary:', ''))

df['min_salary'] = min_hr.apply(lambda x: int(x.split('-')[0]))
df['max_salary'] = min_hr.apply(lambda x: int(x.split('-')[1]))
df['avg_salary'] = (df.min_salary+df.max_salary) / 2

#company name text only
df['company_txt'] = df.apply(lambda x: x['Company Name'] if x['Rating'] < 0 else x['Company Name'][:-3], axis = 1)

#state field 
df['job_state'] = df['Location'].apply(lambda x: x.split(',')[1])
print(df.job_state.value_counts())

df['same_sate'] = df.apply(lambda x: 1 if x.Location == x.Headquarters else 0, axis = 1)

#age of company
df['age'] = df.Founded.apply(lambda x: x if x < 1 else 2020 - x)

#parsing of job description (python, etc.) #print(df['Job Description'][0]) 

#python
df['python_yn'] = df['Job Description'].apply(lambda x: 1 if 'python' in x.lower() else 0)
print('\npython in the job decription', df.python_yn.value_counts())

#r studio
df['R_yn'] = df['Job Description'].apply(lambda x: 1 if 'r studio' in x.lower() or 'r-studio' in x.lower() else 0)
print('\nR in the job decription', df.R_yn.value_counts())

#spark
df['Spark_yn'] = df['Job Description'].apply(lambda x: 1 if 'spark' in x.lower()  else 0)
print('\nSpark in the job decription', df.Spark_yn.value_counts())

#aws
df['aws_yn'] = df['Job Description'].apply(lambda x: 1 if 'aws' in x.lower()  else 0)
print('\naws in the job decription', df.aws_yn.value_counts())

#excel
df['excel_yn'] = df['Job Description'].apply(lambda x: 1 if 'excel' in x.lower()  else 0)
print('\nexcel in the job decription', df.excel_yn.value_counts())

df_out = df.drop(['Unnamed: 0'], axis=1)

df_out.to_csv('salary_data_cleaned.csv', index = False)

#pd.read_csv('salary_data_cleaned.csv')