In [1]:
import pandas as pd
In [2]:
!pip install pandas
Requirement already satisfied (use --upgrade to upgrade): pandas in /usr/local/lib/python3.5/site-packages
Requirement already satisfied (use --upgrade to upgrade): python-dateutil>=2 in /usr/local/lib/python3.5/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /usr/local/lib/python3.5/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /usr/local/lib/python3.5/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /usr/local/lib/python3.5/site-packages (from python-dateutil>=2->pandas)
In [20]:
import pandas as pd
In [21]:
df = pd.read_excel("Billionaire Characteristics Database/richpeople.xlsx")
In [22]:
!pip install xlrd
Requirement already satisfied (use --upgrade to upgrade): xlrd in /usr/local/lib/python3.5/site-packages
In [23]:
df.head(3)
Out[23]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
0
2001
A Jerrold Perenchio
151
United States
USA
3.0
self-made
executive
male
70.0
...
former chairman and CEO
1955.0
1.062180e+13
NaN
represented Marlon Brando and Elizabeth Taylor
NaN
http://en.wikipedia.org/wiki/Jerry_Perenchio
http://www.forbes.com/profile/a-jerrold-perenc...
COLUMN ONE; A Hollywood Player Who Owns the Ga...
NaN
1
2014
A. Jerrold Perenchio
663
United States
USA
2.6
self-made
executive
male
83.0
...
former chairman and CEO
1955.0
NaN
television, Univision
represented Marlon Brando and Elizabeth Taylor
NaN
http://en.wikipedia.org/wiki/Jerry_Perenchio
http://www.forbes.com/profile/a-jerrold-perenc...
COLUMN ONE; A Hollywood Player Who Owns the Ga...
NaN
2
2001
Abdul Al Rahman Al Jeraisy
336
Saudi Arabia
SAU
1.5
self-made
founder non-finance
male
NaN
...
founder
1956.0
1.830120e+11
NaN
NaN
NaN
http://www.jeraisy.com.sa/index.php/pages/rend...
NaN
NaN
NaN
3 rows × 30 columns
In [24]:
df.columns
Out[24]:
Index(['year', 'name', 'rank', 'citizenship', 'countrycode',
'networthusbillion', 'selfmade', 'typeofwealth', 'gender', 'age',
'industry', 'IndustryAggregates', 'region', 'north',
'politicalconnection', 'founder', 'generationofinheritance', 'sector',
'company', 'companytype', 'relationshiptocompany', 'foundingdate',
'gdpcurrentus', 'sourceofwealth', 'notes', 'notes2', 'source',
'source_2', 'source_3', 'source_4'],
dtype='object')
In [25]:
recent = df[df['year'] == 2014]
recent.head(3)
Out[25]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
1
2014
A. Jerrold Perenchio
663
United States
USA
2.6
self-made
executive
male
83.0
...
former chairman and CEO
1955.0
NaN
television, Univision
represented Marlon Brando and Elizabeth Taylor
NaN
http://en.wikipedia.org/wiki/Jerry_Perenchio
http://www.forbes.com/profile/a-jerrold-perenc...
COLUMN ONE; A Hollywood Player Who Owns the Ga...
NaN
5
2014
Abdulla Al Futtaim
687
United Arab Emirates
ARE
2.5
inherited
inherited
male
NaN
...
relation
1930.0
NaN
auto dealers, investments
company split between him and cousin in 2000
NaN
http://en.wikipedia.org/wiki/Al-Futtaim_Group
http://www.al-futtaim.ae/content/groupProfile.asp
NaN
NaN
6
2014
Abdulla bin Ahmad Al Ghurair
305
United Arab Emirates
ARE
4.8
inherited
inherited
male
NaN
...
relation
1960.0
NaN
diversified
inherited from father
NaN
http://en.wikipedia.org/wiki/Al-Ghurair_Group
http://www.alghurair.com/about-us/our-history
NaN
NaN
3 rows × 30 columns
In [61]:
recent['countrycode'].value_counts().head()
#df['animal'].value_counts()
Out[61]:
USA 499
CHN 152
RUS 111
DEU 85
BRA 65
Name: countrycode, dtype: int64
In [27]:
Swiss_billionaires = recent[recent['countrycode'] == 'CHE']
Swiss_billionaires.head(3)
Out[27]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
257
2014
Benjamin de Rothschild
869
Switzerland
CHE
2.0
inherited
inherited
male
50.0
...
relation
1953.0
NaN
banking
member of Rothschild banking family (founded i...
only child
http://en.wikipedia.org/wiki/Benjamin_de_Roths...
http://en.wikipedia.org/wiki/LCF_Rothschild_Group
http://en.wikipedia.org/wiki/Edmond_Adolphe_de...
http://www.nytimes.com/1997/11/04/business/bar...
609
2014
Edgar de Picciotto
1078
Switzerland
CHE
1.7
self-made
self-made finance
male
84.0
...
founder
1969.0
NaN
private banking
NaN
NaN
http://en.wikipedia.org/wiki/Union_Bancaire_Pr...
http://www.ubp.com/en/private-bank/swiss-bank/...
NaN
NaN
676
2014
Ernesto Bertarelli
92
Switzerland
CHE
12.0
inherited
inherited
male
48.0
...
relation
1906.0
NaN
biotech, investments
3rd generation
inherited along with sister, who isn't on the ...
http://en.wikipedia.org/wiki/Ernesto_Bertarelli
http://www.forbes.com/profile/ernesto-bertarelli/
http://www.emdserono.com/en/about_us/history/H...
NaN
3 rows × 30 columns
In [50]:
recent.columns
Out[50]:
Index(['year', 'name', 'rank', 'citizenship', 'countrycode',
'networthusbillion', 'selfmade', 'typeofwealth', 'gender', 'age',
'industry', 'IndustryAggregates', 'region', 'north',
'politicalconnection', 'founder', 'generationofinheritance', 'sector',
'company', 'companytype', 'relationshiptocompany', 'foundingdate',
'gdpcurrentus', 'sourceofwealth', 'notes', 'notes2', 'source',
'source_2', 'source_3', 'source_4'],
dtype='object')
In [52]:
recent.sort_values(by='age').head(5)
Out[52]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
1838
2014
Perenna Kei
1284
Hong Kong
HKG
1.3
inherited
inherited
female
24.0
...
relation
1996.0
NaN
real estate
inherited from father
NaN
http://en.wikipedia.org/wiki/Perenna_Kei
http://www.loganestate.com/en/about.aspx?ftid=294
NaN
NaN
605
2014
Dustin Moskovitz
202
United States
USA
6.8
self-made
founder non-finance
male
29.0
...
founder
2004.0
NaN
Facebook
NaN
NaN
http://en.wikipedia.org/wiki/Dustin_Moskovitz
http://www.forbes.com/profile/dustin-moskovitz/
https://www.facebook.com/facebook/info?tab=pag...
NaN
1586
2014
Mark Zuckerberg
21
United States
USA
28.5
self-made
founder non-finance
male
29.0
...
founder
2004.0
NaN
Facebook
NaN
NaN
http://www.forbes.com/profile/mark-zuckerberg/
NaN
NaN
NaN
189
2014
Anton Kathrein, Jr.
1270
Germany
DEU
1.4
inherited
inherited
male
29.0
...
relation
1919.0
NaN
antennas
3rd generation
NaN
http://www.forbes.com/profile/anton-kathrein-jr/#
NaN
NaN
NaN
602
2014
Drew Houston
1372
United States
USA
1.2
self-made
founder non-finance
male
30.0
...
founder
2007.0
NaN
Dropbox
NaN
NaN
http://en.wikipedia.org/wiki/Drew_Houston
http://en.wikipedia.org/wiki/Dropbox_(service)
http://www.forbes.com/profile/drew-houston/
NaN
5 rows × 30 columns
In [54]:
recent.sort_values(by='age', ascending = False).head(5)
Out[54]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
516
2014
David Rockefeller, Sr.
580
United States
USA
2.9
inherited
inherited
male
98.0
...
relation
1870.0
NaN
oil, banking
family made most of fortune in the late 19th a...
NaN
http://en.wikipedia.org/wiki/David_Rockefeller
http://en.wikipedia.org/wiki/Standard_Oil
http://en.wikipedia.org/wiki/Rockefeller_family
NaN
1277
2014
Karl Wlaschek
305
Austria
AUT
4.8
self-made
founder non-finance
male
96.0
...
founder
1953.0
NaN
retail
NaN
NaN
http://en.wikipedia.org/wiki/BILLA
http://en.wikipedia.org/wiki/Karl_Wlaschek
https://www.billa.at/Footer_Nav_Seiten/Geschic...
NaN
1328
2014
Kirk Kerkorian
328
United States
USA
4.5
self-made
self-made finance
male
96.0
...
investor
1924.0
NaN
casinos, investments
purchased in 1969
NaN
http://en.wikipedia.org/wiki/Kirk_Kerkorian
http://www.forbes.com/profile/kirk-kerkorian/
PROFILE: Las Vegas billionaire amassed his wea...
NaN
921
2014
Henry Hillman
687
United States
USA
2.5
inherited
inherited
male
95.0
...
relation
1942.0
NaN
investments
inherited from father
NaN
http://www.forbes.com/profile/henry-hillman/
http://en.wikipedia.org/wiki/Calgon_Carbon
NaN
NaN
666
2014
Erika Pohl-Stroher
1154
Germany
DEU
1.5
inherited
inherited
female
95.0
...
relation
1880.0
NaN
hair products
3rd generation
23% stake in the company
http://www.forbes.com/profile/erika-pohl-stroher/
http://en.wikipedia.org/wiki/Wella
NaN
NaN
5 rows × 30 columns
In [55]:
recent.sort_values(by='networthusbillion', ascending = False).head(5)
Out[55]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
284
2014
Bill Gates
1
United States
USA
76.0
self-made
founder non-finance
male
58.0
...
founder
1975.0
NaN
Microsoft
NaN
NaN
http://www.forbes.com/profile/bill-gates/
NaN
NaN
NaN
348
2014
Carlos Slim Helu
2
Mexico
MEX
72.0
self-made
privatized and resources
male
74.0
...
founder
1990.0
NaN
telecom
NaN
NaN
http://www.ozy.com/provocateurs/carlos-slims-w...
NaN
NaN
NaN
124
2014
Amancio Ortega
3
Spain
ESP
64.0
self-made
founder non-finance
male
77.0
...
founder
1975.0
NaN
retail
NaN
NaN
http://www.forbes.com/profile/amancio-ortega/
NaN
NaN
NaN
2491
2014
Warren Buffett
4
United States
USA
58.2
self-made
founder non-finance
male
83.0
...
founder
1839.0
NaN
Berkshire Hathaway
NaN
NaN
http://www.forbes.com/lists/2009/10/billionair...
http://www.forbes.com/companies/berkshire-hath...
NaN
NaN
1377
2014
Larry Ellison
5
United States
USA
48.0
self-made
founder non-finance
male
69.0
...
founder
1977.0
NaN
Oracle
NaN
NaN
http://www.forbes.com/profile/larry-ellison/
http://www.businessinsider.com/how-larry-ellis...
NaN
NaN
5 rows × 30 columns
In [76]:
recent.groupby(['countrycode'])['networthusbillion'].mean().sort_values(ascending = False).head(15)
Out[76]:
countrycode
MEX 8.931250
NGA 8.325000
COL 7.650000
SAU 7.000000
SWE 6.142105
FRA 5.472093
GEO 5.200000
IRL 5.100000
CYP 4.925000
NZL 4.900000
HKG 4.748889
DEU 4.722353
ESP 4.715385
USA 4.654108
ITA 4.517143
Name: networthusbillion, dtype: float64
*Where is the oldest money?
In [80]:
recent.groupby(['generationofinheritance']).count()
Out[80]:
year
name
rank
citizenship
countrycode
networthusbillion
selfmade
typeofwealth
gender
age
...
relationshiptocompany
foundingdate
gdpcurrentus
sourceofwealth
notes
notes2
source
source_2
source_3
source_4
generationofinheritance
0
1151
1151
1151
1151
1151
1151
1149
1149
1151
1117
...
1149
1139
0
1134
182
6
1151
1048
404
10
Fifth generation or longer
15
15
15
15
15
15
15
15
15
15
...
15
15
0
15
15
3
15
13
6
0
Fourth generation
33
33
33
33
33
33
33
33
33
33
...
33
33
0
33
33
4
33
25
8
1
Third generation
100
100
100
100
100
100
100
100
100
92
...
100
100
0
100
99
24
100
73
24
1
inherited from father
316
316
316
316
316
316
316
316
316
298
...
316
316
0
316
316
67
316
233
74
4
spouse or widow
38
38
38
38
38
38
38
38
38
35
...
38
38
0
38
38
7
38
24
7
1
6 rows × 29 columns
In [81]:
recent[recent['generationofinheritance'] == 'Fith generation or longer']
df[df['POS'] == 'G']
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
1944 try:
-> 1945 return self._engine.get_loc(key)
1946 except KeyError:
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)()
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)()
pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)()
pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)()
KeyError: False
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-81-faf0cb14a3a6> in <module>()
----> 1 recent['generationofinheritance' == 'Fith generation or longer']
/usr/local/lib/python3.5/site-packages/pandas/core/frame.py in __getitem__(self, key)
1995 return self._getitem_multilevel(key)
1996 else:
-> 1997 return self._getitem_column(key)
1998
1999 def _getitem_column(self, key):
/usr/local/lib/python3.5/site-packages/pandas/core/frame.py in _getitem_column(self, key)
2002 # get column
2003 if self.columns.is_unique:
-> 2004 return self._get_item_cache(key)
2005
2006 # duplicate columns & possible reduce dimensionality
/usr/local/lib/python3.5/site-packages/pandas/core/generic.py in _get_item_cache(self, item)
1348 res = cache.get(item)
1349 if res is None:
-> 1350 values = self._data.get(item)
1351 res = self._box_item_values(item, values)
1352 cache[item] = res
/usr/local/lib/python3.5/site-packages/pandas/core/internals.py in get(self, item, fastpath)
3288
3289 if not isnull(item):
-> 3290 loc = self.items.get_loc(item)
3291 else:
3292 indexer = np.arange(len(self.items))[isnull(self.items)]
/usr/local/lib/python3.5/site-packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
1945 return self._engine.get_loc(key)
1946 except KeyError:
-> 1947 return self._engine.get_loc(self._maybe_cast_indexer(key))
1948
1949 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)()
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)()
pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)()
pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)()
KeyError: False
In [ ]:
Content source: barjacks/foundations-homework
Similar notebooks: