Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 1 project #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions w1/data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,13 @@ def aggregate(self, column_name: str) -> float:
aggregate should be 105.58
"""
######################################## YOUR CODE HERE ##################################################
gen_data_reader = (row for row in self.data_reader)
_= next(gen_data_reader)

aggregate = 0

for row in tqdm(gen_data_reader):
aggregate += self.to_float(row[column_name])
return aggregate

######################################## YOUR CODE HERE ##################################################
16 changes: 16 additions & 0 deletions w1/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def revenue_per_region(dp: DataProcessor) -> Dict:
}
"""
######################################## YOUR CODE HERE ##################################################
gen_data_reader = (row for row in dp.data_reader)

_= next(gen_data_reader)

revenue_per_region = {}

for row in tqdm(gen_data_reader):
country = row['Country']
total_price = dp.to_float((row['TotalPrice']))

if country in revenue_per_region:
revenue_per_region[country] += total_price
else:
revenue_per_region[country] = total_price

return revenue_per_region

######################################## YOUR CODE HERE ##################################################

Expand Down
5 changes: 5 additions & 0 deletions w1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def __iter__(self) -> Generator:
}
"""
######################################## YOUR CODE HERE ##################################################
with open(self._fp, 'r') as f:
rows = f.readlines()
for row in rows:
row = row.strip().split(self._sep)
yield {self._col_names[i]: row[i] for i in range((len(self._col_names)))}

######################################## YOUR CODE HERE ##################################################

Expand Down