Skip to content

Commit 244ec81

Browse files
committed
Final Copy
1 parent 234c95f commit 244ec81

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Assignment5/problem2.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ def calculate_relative_abundance(SiteSpeciesDict):
2727
def get_data_from_web(url):
2828
data = pd.read_csv(url)
2929
return data
30-
BirdData = get_data_from_web('http://www.esapubs.org/archive/ecol/E091/124/TGPP_cover.csv')
30+
3131

3232
#Create a dict for each site by species name and cover
33-
#Sort by Site and Species first
34-
groupedBirdData = BirdData.groupby(['plot','spcode'])
35-
SiteDictOfCoverDict = dict()
36-
SumGroupBirdData = groupedBirdData.sum()
37-
for site in SumGroupBirdData.index.levels[0]:#get a list of indices from group
38-
SiteDictOfCoverDict[site] = dict(SumGroupBirdData.loc[site]['cover'])
33+
def create_sorted_dicts(data):
34+
groupedData = data.groupby(['plot','spcode'])
35+
DictOfDicts = dict()
36+
SumGroupData = groupedData.sum()
37+
for site in SumGroupData.index.levels[0]:#get a list of indices from group
38+
DictOfDicts[site] = dict(SumGroupData.loc[site]['cover'])
39+
return DictOfDicts
3940

40-
#Combinations of Plots
41-
results = []
41+
#Execute Plan
42+
BirdData = get_data_from_web('http://www.esapubs.org/archive/ecol/E091/124/TGPP_cover.csv')
43+
SiteDictOfCoverDict = create_sorted_dicts(BirdData)
4244
CombinationsOfDicts = combinations(SiteDictOfCoverDict.keys(),2)
45+
results = []
4346
for plot1, plot2 in CombinationsOfDicts:
4447
results.append([plot1, plot2, 1-(calculate_Euclidean_distance(SiteDictOfCoverDict[plot1],SiteDictOfCoverDict[plot2]))])
4548
#Write results

0 commit comments

Comments
 (0)