Demo entry 6782469

hm10

   

Submitted by anonymous on Jan 15, 2019 at 09:36
Language: Python 3. Code size: 5.6 kB.

import csv
from collections import defaultdict


revenue= 0
profit= 0
column=0
businesses= defaultdict(dict)
industerys_dict=defaultdict(dict)
industery_count_dict=defaultdict(int)
sector_profit=defaultdict(int)
sectors=[]
industerys=[]
q4=[]
q3=[]
q3_finel=[]
f="C:/Users/DELL/Documents/python/fortune1000.csv"
with open(f,encoding='utf-8') as csvfile:
    redear=csv.DictReader(csvfile)

    header = redear.fieldnames


    # for row in csvfile:
    #     column+= 1
    #     if row[5].isdigit():
    #         revenue+= float(row[5])
    #     if row[6].isdigit():
    #         profit+= float(row [6])

    for row in redear:
        #column =+ 1
        #if row[5].isdigit():
         #   revenue = + float(row[5])
        #if row[6].isdigit():
         #   profit = + float(row[6])

        industery_count= row['Industry']
        industery_count_dict[industery_count]+= 1

        # redear[row['City']], redear[row['State']] = redear[row['Location']].str.split(', ').str

        s_profit= row['Sector']
        sector_profit[s_profit]+= int((row['Profits']))
        # sector_profit[s_profit]['sum_compeny']+=1

        if row['Company'] not in businesses:
            businesses[row['Company']]['company_name']= row['Company']
            businesses[row['Company']]['company_revenue'] = row['Revenue']
            businesses[row['Company']]['company_employees'] = row['Employees']
        if float(businesses[row['Company']]['company_employees']) > float(300000):
            q4.append(businesses[row['Company']]['company_name'])


        if row['Sector'] not in sectors:
            sectors.append(row['Sector'])
        if row['Industry'] not in industerys:
            industerys.append(row['Industry'])

        q3.append(int(businesses[row['Company']]['company_revenue']))
        q3_s=sorted(q3)
        q3_7_revenue= q3_s[-7:]

        if int(businesses[row['Company']]['company_revenue'])in q3_7_revenue:
            q3_finel.append(businesses[row['Company']]['company_name'])



print("answers")
# print(f'q1\n rows {column} column {len(header)}')
# print(f'q2\n mean revenue {revenue/column} mean profit {profit/column}')
print(q3_finel)
print(f'q4\n {q4}')
print(f'q5\n sectors {len(sectors)} industerys {len(industerys)} ')
print(f'q6\n {industery_count_dict}')
print(f'q9\n {sector_profit}')

______________________________________


answers
['Walmart', 'Exxon Mobil', 'Apple', 'Berkshire Hathaway', 'McKesson', 'UnitedHealth Group', 'CVS Health']
q4
 ['Walmart', 'Berkshire Hathaway', 'General Electric', 'Kroger', 'Walgreens Boots Alliance', 'Home Depot', 'IBM', 'Target', 'UPS', 'FedEx', 'McDonald’s', 'Yum Brands']
q5
 sectors 21 industerys 73
q6
 defaultdict(<class 'int'>, {'General Merchandisers': 10, 'Petroleum Refining': 17, 'Computers, Office Equipment': 7, 'Insurance: Property and Casualty (Stock)': 28, 'Wholesalers: Healt
h Care': 6, 'Health Care: Insurance and Managed Care': 11, 'Food and Drug Stores': 15, 'Motor Vehicles and Parts': 24, 'Telecommunications': 15, 'Industrial Machinery': 23, 'Specialty R
etailers: Other': 42, 'Diversified Financials': 15, 'Internet Services and Retailing': 15, 'Health Care: Pharmacy and Other Services': 13, 'Commercial Banks': 28, 'Aerospace and Defense
': 20, 'Computer Software': 14, 'Information Technology Services': 13, 'Household and Personal Products': 13, 'Insurance: Property and Casualty (Mutual)': 7, 'Pharmaceuticals': 15, 'Ins
urance: Life, Health (stock)': 18, 'Food Production': 9, 'Food Consumer Products': 20, 'Mail, Package, and Freight Delivery': 2, 'Semiconductors and Other Electronic Components': 23, 'E
ntertainment': 18, 'Network and Other Communications Equipment': 14, 'Chemicals': 30, 'Wholesalers: Food and Grocery': 6, 'Construction and Farm Machinery': 9, 'Insurance: Life, Health
(Mutual)': 10, 'Beverages': 9, 'Health Care: Medical Facilities': 14, 'Wholesalers: Electronics and Office Equipment': 8, 'Pipelines': 12, 'Airlines': 9, 'Electronics, Electrical Equip.
': 13, 'Specialty Retailers: Apparel': 18, 'Mining, Crude-Oil Production': 28, 'Apparel': 15, 'Wholesalers: Diversified': 25, 'Miscellaneous': 11, 'Utilities: Gas and Electric': 41, 'To
bacco': 5, 'Food Services': 12, 'Computer Peripherals': 4, 'Oil and Gas Equipment, Services': 9, 'Metals': 14, 'Packaging, Containers': 16, 'Railroads': 5, 'Scientific,Photographic and
Control Equipment': 12, 'Automotive Retailing, Services': 10, 'Medical Products and Equipment': 16, 'Temporary Help': 5, 'Engineering, Construction': 14, 'Advertising, marketing': 2, 'E
nergy': 14, 'Hotels, Casinos, Resorts': 13, 'Diversified Outsourcing Services': 14, 'Financial Data Services': 19, 'Transportation and Logistics': 5, 'Waste Management': 5, 'Securities'
: 18, 'Publishing, Printing': 7, 'Home Equipment, Furnishings': 12, 'Real estate': 15, 'Homebuilders': 12, 'Forest and Paper Products': 5, 'Trucking, Truck Leasing': 9, 'Transportation
Equipment': 5, 'Building Materials, Glass': 7, 'Education': 3})
q9
 defaultdict(<class 'int'>, {'Retailing': 47830, 'Energy': -73447, 'Technology': 180473, 'Financials': 260209, 'Health Care': 106114, 'Food and Drug Stores': 16759, 'Motor Vehicles & Pa
rts': 25898, 'Telecommunications': 48637, 'Industrials': 20764, 'Aerospace & Defense': 28742, 'Household Products': 14428, 'Food, Beverages & Tobacco': 51417, 'Transportation': 44169, '
Media': 24347, 'Chemicals': 22628, 'Wholesalers': 8233, 'Apparel': 8236, 'Hotels, Resturants & Leisure': 20697, 'Materials': 4428, 'Business Services': 28227, 'Engineering & Constructio
n': 5304})

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).