<jupyter_start><jupyter_text>DAY 19 - Mar 15, 2015 I have installed a database, imported data, and learned how to extract data. I am now able to ask questions of the data such as what is predictive of high salary.<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
# Load libs
import psycopg2
import pandas.io.sql as pdsql

# Specify our database
dbname="hr"
name_of_table = "survey"

# Connect to database
conn = psycopg2.connect(dbname=dbname)

# Make database query
the_frame = pdsql.read_sql_query("SELECT * FROM %s;" % name_of_table, conn)
the_frame.head()<jupyter_output><empty_output><jupyter_text>What is in my data?<jupyter_code>plt.rcParams["figure.figsize"] = [10,10]
fig, ax = plt.subplots(nrows=3, ncols=3)

the_frame.iloc[:,1:3].plot.box(ax=ax[0,0])

the_frame["average_montly_hours"].plot.kde(ax=ax[0,1])
ax[0,1].set(xlabel = "average_montly_hours")

features = ['number_project', 'time_spend_company', 'work_accident', 'left_workplace', 'promotion_last_5years', 'sales', 'salary']

for i in range(1,3):
    for j in range(3):
        feature = features.pop()
        
        the_frame[feature].value_counts(sort=True).plot(kind='bar', ax=ax[i,j])
        ax[i,j].set(title = feature)

feature = features.pop()
the_frame[feature].value_counts(sort=False).plot(kind='bar', ax=ax[0,2])
ax[0,2].set(title = feature)

plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Answering simple questions:1. Do people who work more hours tend to get higher salary?2. Are people with high salary more happy (higher satisifaction level)? 3. What department has more work accidents? ----<jupyter_code>print("# Mean", the_frame.groupby('salary').average_montly_hours.mean(), sep="\n")
print("", "# Median", the_frame.groupby('salary').average_montly_hours.median(), sep="\n")
fig, ax = plt.subplots(figsize=(8,6))
for label, df in the_frame.groupby('salary'):
    df.average_montly_hours.plot(kind="kde", ax=ax, label=label)
plt.legend()<jupyter_output><empty_output><jupyter_text>People with higher salary does not seem to be working more average_montly_hours----<jupyter_code>print("# Mean", the_frame.groupby('salary').satisfaction_level.mean(), sep="\n")
print("", "# Median", the_frame.groupby('salary').satisfaction_level.median(), sep="\n")
plt.rcParams["figure.figsize"] = [8,6]
the_frame[['satisfaction_level','salary']].boxplot(column="satisfaction_level", by="salary")
plt.ylabel("Satisfaction level")
plt.title("")<jupyter_output><empty_output><jupyter_text>Satisfaction tends to be slightly higher with higher salary.----<jupyter_code>plt.rcParams["figure.figsize"] = [8,6]

# Make database query
the_frame_accident = pdsql.read_sql_query("SELECT * FROM %s WHERE work_accident = 'True';" % name_of_table, conn)
the_frame_accident['sales'].value_counts().plot(kind='bar')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15479548660084627, 'fraction_numerical': 0.014456981664315938, 'mean_word_length': 6.837016574585635, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '77939', 'license': 'MIT', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1005, 'n_words': 209, 'path': 'hr/day19-exploratory-analysis.ipynb', 'repo_name': 'csiu/kaggle', 'size': '2836'}