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

Task 09 #49

Open
wants to merge 2 commits into
base: master
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
21 changes: 15 additions & 6 deletions task-09/get_top_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,28 @@ def __init__(self):
self.records = []
self.year = None

def add(self, name, is_female, rank):
def add(self, name, is_female=None, rank=None):
if self.year is None:
raise ValueError('One must set year first')

# complete this member function
raise NotImplementedError
else:
self.records.append((self.year, is_female, rank, name))

def to_pandas(self):
# complete this member function
raise NotImplementedError
return pd.DataFrame.from_records(self.records, columns=['year', 'gender', 'rank', 'name'])

def clear(self):
self.records.clear()
self.year = None

def to_sql(self, filename=None):
if filename is None:
raise ValueError('One must set a filename!')
else:
with open(filename, 'w') as file:
file.write('year gender rank name\n')
for raw in self.records:
file.write("%s %s %s %s\n" %(raw[0], 'female' if raw[1] else 'male ', raw[2], raw[3]))


if __name__ == '__main__':
filename = '../task-03/top5names.html'
Expand All @@ -66,4 +73,6 @@ def clear(self):

data = recorder.to_pandas()

recorder.to_sql('to_sql.txt')

print(data.query('name == "Emma"').query('rank == 1')['year'].tolist())
Loading