Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_alx_pcz
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
kurs_alx_pcz
Commits
5c058c12
Commit
5c058c12
authored
Dec 11, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grupowanie_v1
parent
8e2510ff
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
p5_grupowanie_v1.py
dzien8/emps2_obiektowo/p5_grupowanie_v1.py
+33
-0
No files found.
dzien8/emps2_obiektowo/p5_grupowanie_v1.py
0 → 100644
View file @
5c058c12
''' Dla każdej wartości job_title, która występuje w danych,
oblicz liczbę pracowników i średnią pensję.
Spodziewane wyniki (może w innej kolejności):
* President - 1 - 24000
* Administation Vice President - 2 - 17000
* Programmer - 5 - 5760
* ... ????
'''
# W tej wersji wielokrotnie przeglądamy cała listę:
# najpierw, aby ustalić, jakie są joby, a następnie dla każdego joba licząc średnią tak, jak w zadaniu 4.
# Ta wersja nie jest optymalna pod względem wydajności.
from
employees
import
read_csv
emps
=
read_csv
(
'emps.csv'
)
# etap 1: zbieranie informacji o jobach
jobs
=
set
()
for
emp
in
emps
:
jobs
.
add
(
emp
.
job_title
)
# print(jobs)
# etap 2: dla każdego joba liczymy liczbę oraz sumę pracowników i wypisujemy średnią
for
job
in
jobs
:
ile
=
0
suma
=
0
for
emp
in
emps
:
if
emp
.
job_title
==
job
:
suma
+=
emp
.
salary
ile
+=
1
srednia
=
suma
/
ile
print
(
f
'| {job:32} | {ile:2} | {srednia:8.2f} |'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment