#python #arrays #for-loop #analyzer
#python #массивы #for-цикл #анализатор
Вопрос:
Где я допустил ошибку в своем коде? Я пытаюсь найти разницу в доходах мужчин и женщин? Вот мой код:
occupation_lst = ['ALL OCCUPATIONS', 'MANAGEMENT', 'Chief executives', 'General and operations managers', 'Marketing and sales managers', 'Administrative services managers', 'Computer and information systems managers', 'Financial managers', 'Human resources managers', 'Industrial production managers', 'Purchasing managers', 'Transportation storage and distribution managers', 'Farmers ranchers and other agricultural managers', 'Construction managers', 'Education administrators', 'Architectural and engineering managers', 'Food service managers', 'Lodging managers', 'Medical and health services managers', 'Property real estate and community association managers', 'Social and community service managers', 'Managers all other', 'BUSINESS', 'Wholesale and retail buyers except farm products', 'Purchasing agents except wholesale retail and farm products', 'Claims adjusters appraisers examiners and investigators', 'Compliance officers', 'Cost estimators', 'Human resources workers', 'Logisticians', 'Management analysts', 'Market research analysts and marketing specialists', 'Business operations specialists all other', 'Accountants and auditors', 'Financial analysts', 'Personal financial advisors', 'Credit counselors and loan officers', 'COMPUTATIONAL', 'Computer systems analysts', 'Information security analysts', 'Computer programmers', 'Software developers applications and systems software', 'Web developers', 'Computer support specialists', 'Database administrators', 'Network and computer systems administrators', 'Computer network architects', 'Computer occupations all other', 'Operations research analysts', 'ENGINEERING', 'Architects except naval', 'Aerospace engineers', 'Chemical engineers', 'Civil engineers', 'Computer hardware engineers', 'Electrical and electronics engineers', 'Industrial engineers including health and safety', 'Mechanical engineers', 'Engineers all other', 'Drafters', 'Engineering technicians except drafters', 'Surveying and mapping technicians', 'SCIENCE', 'Medical scientists', 'Chemists and materials scientists', 'Environmental scientists and geoscientists', 'Physical scientists all other', 'Miscellaneous life physical and social science technicians', 'SOCIAL SERVICE', 'Counselors', 'Social workers', 'Clergy', 'LEGAL', 'Lawyers', 'EDUCATION', 'Postsecondary teachers', 'Elementary and middle school teachers', 'Secondary school teachers', 'Other teachers and instructors', 'ARTS', 'Designers', 'Producers and directors', 'Athletes coaches umpires and related workers', 'Editors', 'Broadcast and sound engineering technicians and radio operators', 'HEALTHCARE PROFESSIONAL', 'Pharmacists', 'Physicians and surgeons', 'Physical therapists', 'Registered nurses', 'Clinical laboratory technologists and technicians', 'Diagnostic related technologists and technicians', 'Emergency medical technicians and paramedics', 'Health practitioner support technologists and technicians', 'HEALTHCARE SUPPORT', 'Nursing psychiatric and home health aides', 'PROTECTIVE SERVICE', 'First-line supervisors of police and detectives', 'First-line supervisors of protective service workers all other', 'Firefighters', 'Bailiffs correctional officers and jailers', 'Detectives and criminal investigators', "Police and sheriff's patrol officers", 'Security guards and gaming surveillance officers', 'CULINARY', 'Chefs and head cooks', 'First-line supervisors of food preparation and serving workers', 'Cooks', 'Food preparation workers', 'Bartenders', 'Combined food preparation and serving workers including fast food', 'Waiters and waitresses', 'Dining room and cafeteria attendants and bartender helpers', 'Dishwashers', 'GROUNDSKEEPING', 'First-line supervisors of housekeeping and janitorial workers', 'First-line supervisors of landscaping lawn service and groundskeeping workers', 'Janitors and building cleaners', 'Maids and housekeeping cleaners', 'Pest control workers', 'Grounds maintenance workers', 'SERVICE', 'First-line supervisors of gaming workers', 'Baggage porters bellhops and concierges', 'Personal care aides', 'Recreation and fitness workers', 'SALES', 'First-line supervisors of retail sales workers', 'First-line supervisors of non-retail sales workers', 'Cashiers', 'Parts salespersons', 'Retail salespersons', 'Advertising sales agents', 'Insurance sales agents', 'Securities commodities and financial services sales agents', 'Sales representatives services all other', 'Sales representatives wholesale and manufacturing', 'Real estate brokers and sales agents', 'Sales and related workers all other', 'OFFICE', 'First-line supervisors of office and administrative support workers', 'Bill and account collectors', 'Bookkeeping accounting and auditing clerks', 'Customer service representatives', 'Hotel motel and resort desk clerks', 'Receptionists and information clerks', 'Couriers and messengers', 'Dispatchers', 'Postal service clerks', 'Postal service mail carriers', 'Production planning and expediting clerks', 'Shipping receiving and traffic clerks', 'Stock clerks and order fillers', 'Secretaries and administrative assistants', 'Data entry keyers', 'Insurance claims and policy processing clerks', 'Office clerks general', 'Office and administrative support workers all other', 'AGRICULTURAL', 'Miscellaneous agricultural workers', 'CONSTRUCTION', 'First-line supervisors of construction trades and extraction workers', 'Brickmasons blockmasons and stonemasons', 'Carpenters', 'Carpet floor and tile installers and finishers', 'Construction laborers', 'Operating engineers and other construction equipment operators', 'Drywall installers ceiling tile installers and tapers', 'Electricians', 'Painters construction and maintenance', 'Pipelayers plumbers pipefitters and steamfitters', 'Roofers', 'Sheet metal workers', 'Structural iron and steel workers', 'Construction and building inspectors', 'Highway maintenance workers', 'Mining machine operators', 'Other extraction workers', 'MAINTENANCE', 'First-line supervisors of mechanics installers and repairers', 'Computer automated teller and office machine repairers', 'Radio and telecommunications equipment installers and repairers', 'Security and fire alarm systems installers', 'Aircraft mechanics and service technicians', 'Automotive body and related repairers', 'Automotive service technicians and mechanics', 'Bus and truck mechanics and diesel engine specialists', 'Heavy vehicle and mobile equipment service technicians and mechanics', 'Miscellaneous vehicle and mobile equipment mechanics installers and repairers', 'Heating air conditioning and refrigeration mechanics and installers', 'Industrial and refractory machinery mechanics', 'Maintenance and repair workers general', 'Electrical power-line installers and repairers', 'Telecommunications line installers and repairers', 'Precision instrument and equipment repairers', 'Other installation maintenance and repair workers', 'PRODUCTION', 'First-line supervisors of production and operating workers', 'Electrical electronics and electromechanical assemblers', 'Miscellaneous assemblers and fabricators', 'Bakers', 'Butchers and other meat poultry and fish processing workers', 'Food processing workers all other', 'Computer control programmers and operators', 'Cutting punching and press machine setters operators and tenders metal and plastic', 'Machinists', 'Welding soldering and brazing workers', 'Metal workers and plastic workers all other', 'Printing press operators', 'Laundry and dry-cleaning workers', 'Stationary engineers and boiler operators', 'Water and wastewater treatment plant and system operators', 'Chemical processing machine setters operators and tenders', 'Crushing grinding polishing mixing and blending workers', 'Inspectors testers sorters samplers and weighers', 'Packaging and filling machine operators and tenders', 'Painting workers', 'Production workers all other', 'TRANSPORTATION', 'Supervisors of transportation and material moving workers', 'Aircraft pilots and flight engineers', 'Bus drivers', 'Driver/sales workers and truck drivers', 'Taxi drivers and chauffeurs', 'Railroad conductors and yardmasters', 'Automotive and watercraft service attendants', 'Crane and tower operators', 'Industrial truck and tractor operators', 'Cleaners of vehicles and equipment', 'Laborers and freight stock and material movers hand', 'Packers and packagers hand', 'Refuse and recyclable material collectors']
m_weekly_lst = [895, 1486, 2251, 1347, 1603, 1451, 1817, 1732, 1495, 1528, 1404, 1006, 847, 1357, 1585, 1892, 820, 1171, 1422, 1137, 1142, 1525, 1327, 886, 1020, 1134, 1375, 1264, 1158, 1075, 1519, 1411, 1461, 1345, 1680, 1738, 1186, 1503, 1462, 1562, 1501, 1751, 1233, 1135, 1829, 1266, 1577, 1252, 1574, 1452, 1492, 1668, 1583, 1474, 1871, 1819, 1430, 1550, 1537, 977, 984, 1031, 1379, 1362, 1496, 1740, 1770, 1001, 973, 908, 943, 1021, 1877, 1914, 1144, 1405, 1077, 1149, 1024, 1088, 1099, 1340, 818, 1205, 937, 1272, 2117, 1915, 1347, 1222, 1089, 1106, 899, 652, 577, 526, 851, 1425, 825, 1052, 779, 1265, 1001, 592, 481, 656, 621, 427, 414, 569, 401, 501, 389, 401, 517, 700, 653, 547, 475, 591, 473, 597, 900, 606, 537, 684, 880, 825, 1140, 471, 600, 694, 1155, 1028, 1461, 1147, 1066, 1052, 1088, 693, 878, 674, 690, 690, 486, 619, 750, 759, 974, 1021, 978, 604, 537, 786, 589, 762, 609, 852, 477, 460, 751, 1047, 652, 687, 634, 642, 859, 595, 891, 587, 862, 580, 776, 864, 965, 755, 1098, 918, 842, 1033, 865, 879, 913, 1032, 849, 724, 830, 928, 591, 810, 894, 771, 1105, 880, 1009, 810, 729, 924, 566, 637, 570, 582, 679, 857, 674, 840, 767, 678, 729, 487, 1012, 868, 1082, 668, 844, 605, 733, 666, 679, 898, 1830, 681, 751, 600, 1137, 470, 1016, 612, 498, 547, 462, 496]
f_weekly_lst = [726, 1139, 1836, 1002, 1258, 981, 1563, 1130, 1274, 0, 1226, 749, 0, 0, 1252, 0, 680, 902, 1156, 823, 965, 1213, 1004, 985, 986, 824, 1025, 0, 984, 0, 1348, 1239, 969, 988, 1171, 1033, 906, 1245, 1256, 0, 1302, 1415, 1026, 908, 0, 0, 0, 1145, 1325, 1257, 0, 0, 0, 0, 0, 0, 0, 0, 1448, 0, 827, 0, 1067, 1082, 0, 0, 1170, 780, 845, 902, 862, 924, 1135, 1717, 907, 1144, 957, 1006, 817, 942, 918, 1234, 0, 1125, 0, 991, 1811, 1533, 1215, 1098, 796, 908, 0, 633, 490, 457, 655, 0, 0, 0, 686, 0, 1009, 515, 414, 492, 458, 400, 388, 493, 380, 411, 0, 0, 419, 571, 0, 429, 407, 0, 0, 475, 680, 0, 441, 526, 578, 614, 896, 405, 0, 494, 729, 717, 767, 699, 917, 735, 727, 646, 781, 648, 692, 604, 467, 569, 0, 655, 833, 854, 732, 566, 506, 683, 638, 675, 622, 718, 437, 398, 704, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 761, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 519, 623, 544, 512, 475, 463, 508, 0, 0, 0, 0, 581, 0, 460, 0, 0, 0, 0, 583, 482, 0, 501, 494, 0, 0, 572, 632, 0, 0, 0, 0, 0, 0, 455, 424, 0]
missing_data_occupations = []
for line in occupation_lst, m_weekly_lst, f_weekly_lst:
col = line.split()
if col[6]!='Na' and col[4]!='Na':
occupation_lst= col[0]
m_weekly_lst = int(col[4])
f_weekly_lst = int(col[6])
salary_diff =abs(m_weekly_lst-f_weekly_lst)
print(occupation_lst ' -- Males: ' str(m_weekly_lst) ', Females: ' str(f_weekly_lst) ', Income difference: ' str(salary_diff))
else:
missing_data_occupations.apped(col[0])
print()
print(len(missing_data_occupations), 'occupations with no income data')
for occ in missing_data_occupations:
print(occ)
Комментарии:
1. Вы имеете в виду, почему вы не можете разделить строку? Если это так, то это потому, что вы не можете разделить списки только на строки.
2. Как я могу разделить из строк?
3. Что вы имеете в виду? вы хотите разделить список на более мелкие списки?
4. Я хотел, чтобы результат был чем-то вроде изображения (см. Мою правку)
Ответ №1:
Вы можете попробовать это:
for x in range (0,len(occupation_lst)):
col_occ = occupation_lst[x]
col_m = m_weekly_lst[x]
col_f = f_weekly_lst[x]
diff = abs(col_m - col_f)
if col_m > col_f:
status = "Female workers make $" str(diff) "/week less than Female workers."
elif col_m < col_f:
status = "Female workers make $" str(diff) "/week more than Male workers."
else:
status = "Both Male and Female workers make same amount of salary $" str(diff)
print (col_occ ": " status)
Ответ №2:
если вы просто хотите получить разницу между этими двумя списками, вы можете использовать функцию zip.
diff_income= [abs(x - y) for x, y in zip(m_weekly_lst, f_weekly_lst)]
print(diff_income)
Комментарии:
1. Да, но мне нужно включить профессии для каждого из них