Statement of Completion#7b0b0713
Intro to Pandas for Data Analysis
easy
Vectorized Operations with Series
Resolution
Activities
In [1]:
import pandas as pd
In [2]:
companies = [
'Apple', 'Samsung', 'Alphabet', 'Foxconn',
'Microsoft', 'Huawei', 'Dell Technologies',
'Meta', 'Sony', 'Hitachi', 'Intel',
'IBM', 'Tencent', 'Panasonic'
]
In [3]:
revenue_in_millions = pd.Series([
274515, 200734, 182527, 181945, 143015,
129184, 92224, 85965, 84893, 82345,
77867, 73620, 69864, 63191],
index=companies,
name="Top Technology Companies by Revenue")
Understanding Vectorized Operations¶
We'll now compute the revenue in Billions:
In [4]:
revenue_in_billions = revenue_in_millions / 1000
In [5]:
revenue_in_billions
Out[5]:
Apple 274.515 Samsung 200.734 Alphabet 182.527 Foxconn 181.945 Microsoft 143.015 Huawei 129.184 Dell Technologies 92.224 Meta 85.965 Sony 84.893 Hitachi 82.345 Intel 77.867 IBM 73.620 Tencent 69.864 Panasonic 63.191 Name: Top Technology Companies by Revenue, dtype: float64
Activities¶
Subtract $50B from all companies in revenue_in_billions
¶
In [13]:
revenue_recession = revenue_in_billions - 50
revenue_recession
Out[13]:
Apple 224.515 Samsung 150.734 Alphabet 132.527 Foxconn 131.945 Microsoft 93.015 Huawei 79.184 Dell Technologies 42.224 Meta 35.965 Sony 34.893 Hitachi 32.345 Intel 27.867 IBM 23.620 Tencent 19.864 Panasonic 13.191 Name: Top Technology Companies by Revenue, dtype: float64
Create a new series expressing revenue in dollars (units)¶
In [17]:
revenue_in_dollars = revenue_in_millions * 1_000_000
Operations between Series¶
In [19]:
recession_impact = pd.Series([
0.91, 0.93, 0.98, 0.97, 0.99, 0.89, 0.87,
0.82, 0.93, 0.93, 0.89, 0.97, 0.97, 0.94], index=companies)
recession_impact
Out[19]:
Apple 0.91 Samsung 0.93 Alphabet 0.98 Foxconn 0.97 Microsoft 0.99 Huawei 0.89 Dell Technologies 0.87 Meta 0.82 Sony 0.93 Hitachi 0.93 Intel 0.89 IBM 0.97 Tencent 0.97 Panasonic 0.94 dtype: float64
The result of applying the recession impact:
In [20]:
revenue_in_millions * recession_impact
Out[20]:
Apple 249808.65 Samsung 186682.62 Alphabet 178876.46 Foxconn 176486.65 Microsoft 141584.85 Huawei 114973.76 Dell Technologies 80234.88 Meta 70491.30 Sony 78950.49 Hitachi 76580.85 Intel 69301.63 IBM 71411.40 Tencent 67768.08 Panasonic 59399.54 dtype: float64
We can calculate the dollar amount of the impact by combining multiple operations:
In [21]:
# Absolute impact in Millions
revenue_in_millions - (revenue_in_millions * recession_impact)
Out[21]:
Apple 24706.35 Samsung 14051.38 Alphabet 3650.54 Foxconn 5458.35 Microsoft 1430.15 Huawei 14210.24 Dell Technologies 11989.12 Meta 15473.70 Sony 5942.51 Hitachi 5764.15 Intel 8565.37 IBM 2208.60 Tencent 2095.92 Panasonic 3791.46 dtype: float64
In [22]:
# Absolute impact in Billions
(revenue_in_millions - (revenue_in_millions * recession_impact)) / 1_000
Out[22]:
Apple 24.70635 Samsung 14.05138 Alphabet 3.65054 Foxconn 5.45835 Microsoft 1.43015 Huawei 14.21024 Dell Technologies 11.98912 Meta 15.47370 Sony 5.94251 Hitachi 5.76415 Intel 8.56537 IBM 2.20860 Tencent 2.09592 Panasonic 3.79146 dtype: float64
Activities¶
Calculate revenue per employee, in dollars¶
In [24]:
number_of_employees = pd.Series([
164000, 266673, 150028, 1290000, 221000, 195000,
165000, 71970, 109700, 368250, 121100, 282100, 112771, 240198
], index=companies)
In [26]:
number_of_employees
Out[26]:
Apple 164000 Samsung 266673 Alphabet 150028 Foxconn 1290000 Microsoft 221000 Huawei 195000 Dell Technologies 165000 Meta 71970 Sony 109700 Hitachi 368250 Intel 121100 IBM 282100 Tencent 112771 Panasonic 240198 dtype: int64
In [ ]:
In [31]:
revenue_per_employee = (revenue_in_millions / number_of_employees) * 1_000_000
revenue_per_employee
Out[31]:
Apple 1.673872e+06 Samsung 7.527346e+05 Alphabet 1.216620e+06 Foxconn 1.410426e+05 Microsoft 6.471267e+05 Huawei 6.624821e+05 Dell Technologies 5.589333e+05 Meta 1.194456e+06 Sony 7.738651e+05 Hitachi 2.236117e+05 Intel 6.429975e+05 IBM 2.609713e+05 Tencent 6.195210e+05 Panasonic 2.630788e+05 dtype: float64