# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] colab_type="text" id="uJ5KYjiPV5Ul"
# ## Upload the Data and Read the .csv File

# + colab={} colab_type="code" id="PNqLi9vgJh97"
import pandas as pd

# + colab={} colab_type="code" id="FLXFmF4tbobK"
df = pd.read_csv('salaries_by_college_major.csv')

# + colab={"base_uri": "https://localhost:8080/", "height": 254} colab_type="code" id="sHIcvGzlbuVR" outputId="87d4d2d4-771c-47a4-d494-063e99719830"
df.head()

# + [markdown] colab_type="text" id="KH2jLKmvWB0r"
# # Data Exploration and Data Cleaning

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="HngjSfIXfXZ-" outputId="71faea81-b9f1-4c3a-bbe1-63bdbcc22046"
df.shape

# + colab={"base_uri": "https://localhost:8080/", "height": 87} colab_type="code" id="nbHfTGssi5dr" outputId="39170bbc-3f31-4780-cdd4-ded2ee7e69b2"
df.columns

# + colab={"base_uri": "https://localhost:8080/", "height": 1000} colab_type="code" id="Lwc7l1ZsjXkt" outputId="4906b6ea-69fd-4251-9f8e-07a40ea5a9b2"
df.isna()

# + colab={"base_uri": "https://localhost:8080/", "height": 254} colab_type="code" id="gOxwMshdk207" outputId="18813420-e206-492c-b764-43993a162ce4"
df.tail()

# + colab={"base_uri": "https://localhost:8080/", "height": 237} colab_type="code" id="ag1fbMC0ltur" outputId="89562978-4fd9-4f90-d672-001e7a739bd8"
clean_df = df.dropna()
clean_df.tail()

# + [markdown] colab_type="text" id="oaKtSQloWVC2"
# # Accessing Columns and Individual Cells

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="jmG-K0HPnrO3" outputId="9a912aec-faa2-4088-fc0a-ccaf1bc8c755"
clean_df['Starting Median Salary'].max()

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="PAoOp9r8nsKo" outputId="1aa912e9-8853-41d1-894c-fcd75a38ebd5"
clean_df['Starting Median Salary'].idxmax()

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="MzEgHdhZodAq" outputId="6838f938-c30b-4702-a641-d694dbbccc45"
clean_df['Starting Median Salary'][43]

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="A8RqDxtto48F" outputId="5b2af713-db39-4ca2-8cd4-9748ca157af2"
clean_df['Undergraduate Major'].loc[43]

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="CPXcE9mRpFnL" outputId="e1301364-1db9-4aa1-e80e-b0216da72e9c"
clean_df['Undergraduate Major'][43]

# + colab={"base_uri": "https://localhost:8080/", "height": 139} colab_type="code" id="Se2YRmsypgqw" outputId="f9e227c3-f8dd-491b-ab0c-c348597f1941"
clean_df.loc[43]

# + [markdown] colab_type="text" id="18_KA7l7WfDh"
# # Solution: Highest and Lowest Earning Degrees

# + colab={"base_uri": "https://localhost:8080/", "height": 70} colab_type="code" id="_EvDORASpjDu" outputId="aea89f79-8b4e-4f58-cc08-31b1b5491f1d"
print(clean_df['Mid-Career Median Salary'].max())
print(f"Index for the max mid career salary: {clean_df['Mid-Career Median Salary'].idxmax()}")
clean_df['Undergraduate Major'][8]

# + colab={"base_uri": "https://localhost:8080/", "height": 53} colab_type="code" id="dQGN8gZntL2V" outputId="158735d8-5211-4d2d-87cb-d1d89d8cf7bf"
print(clean_df['Starting Median Salary'].min())
clean_df['Undergraduate Major'].loc[clean_df['Mid-Career Median Salary'].idxmin()]

# + colab={"base_uri": "https://localhost:8080/", "height": 134} colab_type="code" id="Z0rvJWSdtNN5" outputId="0752a3cd-7cee-43d3-c67f-bf0e8d193f77"
clean_df.loc[clean_df['Mid-Career Median Salary'].idxmin()]

# + [markdown] colab_type="text" id="cd_pPQo7Wkxi"
# # Sorting Values & Adding Columns: Majors with the Most Potential vs Lowest Risk

# + colab={"base_uri": "https://localhost:8080/", "height": 246} colab_type="code" id="Pqw8VPbEtpcR" outputId="a332506c-14ff-4f1e-891b-d8c1038ed855"
# clean_df['Mid-Career 90th Percentile Salary'] - clean_df['Mid-Career 10th Percentile Salary']
# clean_df['Mid-Career 90th Percentile Salary'].subtract(clean_df['Mid-Career 10th Percentile Salary'])
spread_col = clean_df['Mid-Career 90th Percentile Salary'] - clean_df['Mid-Career 10th Percentile Salary']
clean_df.insert(1, 'Spread', spread_col)
clean_df.head()

# + colab={"base_uri": "https://localhost:8080/", "height": 198} colab_type="code" id="uBokcGx_uj6R" outputId="cb8844eb-bb11-41bb-9e35-11976b0825e0"
low_risk = clean_df.sort_values('Spread')
low_risk[['Undergraduate Major', 'Spread']].head()

# + [markdown] colab_type="text" id="hQBSdbJIWqJY"
# # Solution: Degrees with the Highest Potential

# + colab={"base_uri": "https://localhost:8080/", "height": 198} colab_type="code" id="SShtBkCQKk3O" outputId="255630c1-7a9b-4a3a-98c2-5576dbe75edb"
highest_potential = clean_df.sort_values('Mid-Career 90th Percentile Salary', ascending=False)
highest_potential[['Undergraduate Major', 'Mid-Career 90th Percentile Salary']].head()

# + colab={"base_uri": "https://localhost:8080/", "height": 198} colab_type="code" id="C1hg41AqOkk3" outputId="93369249-a2ca-47b7-e2ab-e391ee3c0c6f"
highest_spread = clean_df.sort_values('Spread', ascending=False)
highest_spread[['Undergraduate Major', 'Spread']].head()

# + colab={"base_uri": "https://localhost:8080/", "height": 198} colab_type="code" id="kKeiNcrzO-K5" outputId="6a3ed661-c488-44f8-f1ad-2bfc79da410b"
highest_spread = clean_df.sort_values('Mid-Career Median Salary', ascending=False)
highest_spread[['Undergraduate Major', 'Mid-Career Median Salary']].head()

# + [markdown] colab_type="text" id="xG7RuPajWwkN"
# # Grouping and Pivoting Data with Pandas

# + colab={"base_uri": "https://localhost:8080/", "height": 185} colab_type="code" id="LKAVOVJTP5iQ" outputId="28c99020-fd35-4822-c6cb-714535f7efbd"
clean_df.groupby('Group').count()

# + colab={"base_uri": "https://localhost:8080/", "height": 185} colab_type="code" id="2PPBqgJbRR_a" outputId="c7421637-e853-4a65-b076-eb35e2ca7063"
pd.options.display.float_format = '{:,.2f}'.format
clean_df.groupby('Group').mean()

# + colab={} colab_type="code" id="jMkNL2nGR6ia"


StarcoderdataJupyterScriptsDedupFiltered