Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_load_data/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_load_data/__pycache__/build.cpython-36.pyc
Binary file not shown.
7 changes: 5 additions & 2 deletions q01_load_data/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pandas as pd


path = 'data/excel-comp-data.xlsx'
def q01_load_data(path):
"write your solution here"
df = pd.read_excel(path)
df['state'] = df['state'].str.lower()
df['total'] = df['Jan'] + df['Feb'] + df['Mar']
return df
Binary file modified q01_load_data/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_load_data/tests/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file modified q02_append_row/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_append_row/__pycache__/build.cpython-36.pyc
Binary file not shown.
23 changes: 14 additions & 9 deletions q02_append_row/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import pandas as pd
import sys, os
#sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q01_load_data.build import q01_load_data


sys.path.append(os.path.join(os.path.dirname(os.curdir)))
#from greyatomlib.pandas_guided_project.q01_load_data.build import q01_load_data
from q01_load_data.build import q01_load_data
path = 'data/excel-comp-data.xlsx'
def q02_append_row(path):
"write your solution here"




df = q01_load_data(path)
df1 = df[['Jan', 'Feb', 'Mar', 'total']].sum(axis=0)
df1 = pd.DataFrame(df1)
df2 = pd.DataFrame(columns=['Jan', 'Feb', 'Mar', 'total'])
df2['Jan'] = df1.loc['Jan']
df2['Feb'] = df1.loc['Feb']
df2['Mar'] = df1.loc['Mar']
df2['total'] = df1.loc['total']
df3 = df.append(df2, ignore_index=True)
return df3
Binary file modified q02_append_row/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_append_row/tests/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file modified q03_scrape_clean/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_scrape_clean/__pycache__/build.cpython-36.pyc
Binary file not shown.
24 changes: 22 additions & 2 deletions q03_scrape_clean/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@
import requests
sys.path.append(os.path.join(os.path.dirname(os.curdir)))


path = 'https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations'
def q03_scrape_clean(url):
"write your solution here"
page = requests.get(url)
df = pd.read_html(page.text)
df1 = df[0].iloc[11:,0]
df2 = df[0].iloc[11:,1]
df3 = df[0].iloc[11:,2]
df4 = df[0].iloc[11:,3]

df5 = df[0].iloc[11:,4]
df6 = df[0].iloc[11:,5]
df7 = df[0].iloc[11:,6]
df8 = df[0].iloc[11:,7]
df9 = df[0].iloc[11:,8]
df10 = df[0].iloc[11:,9]
ans = pd.concat([df1,df2,df3,df4,df5,df6,df7,df8,df9,df10], axis=1)
ans.rename(mapper={0:'Name', 1:'Status', 2:'ISO', 3:'ANSI0', 4:'ANSI1', 5:'USPS', 6:'USCG', 7:'GPO', 8:'AP', 9:'Other Abbrevations'}, inplace=True, axis=1)
ans.drop(ans.index[0], axis=0, inplace=True)
ans['ex1'] = 0
ans['ex2'] = 0
ans['ex3'] = 0
ans['ex4'] = 0
ans['ex5'] = 0
return ans
Binary file modified q03_scrape_clean/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_scrape_clean/tests/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file modified q04_mapping/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q04_mapping/__pycache__/build.cpython-36.pyc
Binary file not shown.
24 changes: 21 additions & 3 deletions q04_mapping/build.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import pandas as pd
import sys, os
import numpy as np
#sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q02_append_row.build import q02_append_row
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from q02_append_row.build import q02_append_row
path1 = 'data/excel-comp-data.xlsx'
path2 = 'data/scraped.csv'

def q04_mapping(path1,path2):
"write your solution here"
df1 = q02_append_row(path1)
df1['abbr'] = np.nan
df2 = pd.read_csv(path2)
ab = df2.iloc[:,7]
name = df2['United States of America']
d = {}
for i in range(0,ab.shape[0]):
d[name[i].lower()] = ab[i]

for i in range(0,df1.shape[0]):
if df1.iloc[i,:]['state'] in d.keys():
df1.iloc[i,-1] = d[df1.iloc[i,:]['state']]

df2 = df1.iloc[:,0:5]
df2['total'] = df1['total']
df2['abbr'] = df1['abbr']
return df2

q04_mapping(path1,path2)
Binary file modified q04_mapping/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q04_mapping/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q05_replace_missing_values/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q05_replace_missing_values/__pycache__/build.cpython-36.pyc
Binary file not shown.
10 changes: 7 additions & 3 deletions q05_replace_missing_values/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import numpy as np
import sys
import os
#sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q04_mapping.build import q04_mapping
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from q04_mapping.build import q04_mapping

path1 = 'data/excel-comp-data.xlsx'
path2 = 'data/scraped.csv'
def q05_replace_missing_values(path1,path2):
df = q04_mapping(path1,path2)
df.iloc[6,6] = 'MS'
df.iloc[10,6] = 'TN'
return df


#print(q05_replace_missing_values(path1,path2).shape)
#q05_replace_missing_values(path1,path2)
Binary file not shown.
Binary file not shown.
Binary file modified q06_sub_total/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q06_sub_total/__pycache__/build.cpython-36.pyc
Binary file not shown.
12 changes: 7 additions & 5 deletions q06_sub_total/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
from sklearn.model_selection import train_test_split
import sys
import os
#sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q05_replace_missing_values.build import q05_replace_missing_values
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from q05_replace_missing_values.build import q05_replace_missing_values

path1 = 'data/excel-comp-data.xlsx'
path2 = 'data/scraped.csv'

def q06_sub_total(path1,path2):
"write your solution here"


df = q05_replace_missing_values(path1,path2)
#print(df)
df1 = df.groupby('abbr').sum()
return df1

#q06_sub_total(path1,path2)
Binary file modified q06_sub_total/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q06_sub_total/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q07_symbols/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q07_symbols/__pycache__/build.cpython-36.pyc
Binary file not shown.
10 changes: 7 additions & 3 deletions q07_symbols/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import sys
import os
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q06_sub_total.build import q06_sub_total
from q06_sub_total.build import q06_sub_total

path1 = 'data/excel-comp-data.xlsx'
path2 = 'data/scraped.csv'

def q07_symbols(path1,path2):
"write your solution here"
df = q06_sub_total(path1,path2)
df1 = df.applymap(lambda x: str('$')+str(x))
df2 = df1.applymap(lambda x: str(x[0:4])+str(',')+str(x[4:]))
return df2

#q07_symbols(path1,path2)


#print(q07_symbols(path1,path2))

#print(q07_symbols(path1,path2))
Binary file modified q07_symbols/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q07_symbols/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q08_append_subtotals/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q08_append_subtotals/__pycache__/build.cpython-36.pyc
Binary file not shown.
33 changes: 28 additions & 5 deletions q08_append_subtotals/build.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import pandas as pd
import numpy as np
import sys,os
#sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q06_sub_total.build import q06_sub_total
from greyatomlib.pandas_guided_project.q07_symbols.build import q07_symbols
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from q06_sub_total.build import q06_sub_total
from q07_symbols.build import q07_symbols


path1 = 'data/excel-comp-data.xlsx'
path2 = 'data/scraped.csv'

def q08_append_subtotals(path1,path2):
"write your solution here"
def comma(x):
if len(str(x)) == 6:
x = str(x)
return str('$')+str(x[0:3])+str(',')+str(x[3:])

elif len(str(x)) == 5:
x = str(x)
return str('$')+str(x[0:2])+str(',')+str(x[2:])

elif len(str(x)) == 7:
x = str(x)
return str('$')+str(x[0])+str(',')+str(x[1:4])+str(',')+str(x[4:])

def q08_append_subtotals(path1,path2):
df = q06_sub_total(path1,path2)
jan = df['Jan'].sum()
feb = df['Feb'].sum()
mar = df['Mar'].sum()
t = df['total'].sum()
a = df['account'].sum()
temp = pd.DataFrame({'Jan':[jan],'Feb':[feb], 'Mar':[mar], 'account':[a], 'total':[t]})
df2 = df.append(temp,ignore_index=True)
dfy = df2.applymap(comma)
dfy.drop('account', axis=1, inplace=True)
return dfy

#q08_append_subtotals(path1,path2)
Binary file modified q08_append_subtotals/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q08_append_subtotals/tests/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file modified q09_pie_chart_jan/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q09_pie_chart_jan/__pycache__/build.cpython-36.pyc
Binary file not shown.
13 changes: 6 additions & 7 deletions q09_pie_chart_jan/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from sklearn.model_selection import train_test_split
import sys,os
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q06_sub_total.build import q06_sub_total
from q06_sub_total.build import q06_sub_total
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.switch_backend('agg')

def q09_pie_chart_jan(path1,path2):

"write your solution here"



df = q06_sub_total(path1,path2)
df.plot(x='Jan', kind='pie', subplots='True')
plt.show()
Binary file modified q09_pie_chart_jan/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q09_pie_chart_jan/tests/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file modified q10_total/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q10_total/__pycache__/build.cpython-36.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions q10_total/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from sklearn.model_selection import train_test_split
import sys,os
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.pandas_guided_project.q06_sub_total.build import q06_sub_total
from q06_sub_total.build import q06_sub_total
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.switch_backend('agg')

def q10_total(path1,path2):

"write your solution here"


df = q06_sub_total(path1,path2)
df.plot(x='Jan', kind='pie', subplots='True')
plt.show()
Binary file modified q10_total/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q10_total/tests/__pycache__/tests.cpython-36.pyc
Binary file not shown.