<jupyter_start><jupyter_text>What country are most billionaires from? For the top ones, how many billionaires per billion people?<jupyter_code>df['citizenship'].value_counts().head()
df.groupby('citizenship')['networthusbillion'].sum().sort_values(ascending=False)
us_pop = 318.9 #billion (2014)
us_bill = df[df['citizenship'] == 'United States']
print("There are",  us_pop/len(us_bill), "billionaires per billion people in the United States.")

germ_pop = 0.08062 #(2013)
germ_bill = df[df['citizenship'] == 'Germany']
print("There are",  germ_pop/len(germ_bill), "billionaires per billion people in Germany.")

china_pop = 1.357 #(2013)
china_bill = df[df['citizenship'] == 'China']
print("There are",  china_pop/len(china_bill), "billionaires per billion people in China.")

russia_pop = 0.1435 #(2013)
russia_bill = df[df['citizenship'] == 'Russia']
print("There are",  russia_pop/len(russia_bill), "billionaires per billion people in Russia.")
japan_pop = 0.1273 # 2013 
japan_bill = df[df['citizenship'] == 'Japan']
print("There are",  japan_pop/len(japan_bill), "billionaires per billion people in Japan.")
print(df.columns)<jupyter_output>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')<jupyter_text>Who are the top 10 richest billionaires?<jupyter_code>recent = df[df['year'] == 2014]
# if it is not recent then there are duplicates for diff years
recent.sort_values('rank').head(10)
recent['networthusbillion'].describe()<jupyter_output><empty_output><jupyter_text>What's the average wealth of a billionaire? Male? Female?  What's the average wealth of a billionaire? Male? Female<jupyter_code>print("The average wealth of a billionaire is", recent['networthusbillion'].mean(), "billion dollars")

male = recent[(recent['gender'] == 'male')]
female = recent[(recent['gender'] == 'female')]


print("The average wealth of a male billionaire is", male['networthusbillion'].mean(), "billion dollars")
print("The average wealth of a female billionaire is", female['networthusbillion'].mean(), "billion dollars")<jupyter_output>The average wealth of a billionaire is 3.90465819722 billion dollars
The average wealth of a male billionaire is 3.9027155465 billion dollars
The average wealth of a female billionaire is 3.92055555556 billion dollars<jupyter_text>Who is the poorest billionaire?<jupyter_code>recent.sort_values('networthusbillion').head(1)
# Who are the top 10 poorest billionaires?
# Who are the top 10 poorest billionaires
recent.sort_values('networthusbillion').head(10)
# 'What is relationship to company'? And what are the most common relationships?
#top 10 most common relationships to company
df['relationshiptocompany'].value_counts().head(10)
# Most common source of wealth? Male vs. female?
# Most common source of wealth? Male vs. female
print("The most common source of wealth is", df['sourceofwealth'].value_counts().head(1))
print("The most common source of wealth for males is", male['sourceofwealth'].value_counts().head(1))
print("The most common source of wealth for females is", female['sourceofwealth'].value_counts().head(1))

#need to figure out how to extract just the number nd not the data type 'Name: sourceofwealth, dtype: int64'<jupyter_output>The most common source of wealth is real estate    107
Name: sourceofwealth, dtype: int64
The most common source of wealth for males is real estate    100
Name: sourceofwealth, dtype: int64
The most common source of wealth for females is diversified    9
Name: sourceofwealth, dtype: int64<jupyter_text>Given the richest person in a country, what % of the GDP is their wealth?<jupyter_code>richest = df[df['citizenship'] == 'United States'].sort_values('rank').head(1)['networthusbillion'].to_dict()
# richest['networthusbillion']
richest[282]

## I JUST WANT THE VALUE -- 18.5.

## 16.77 TRILLION
US_GDP = 1.677 * (10^13)
US_GDP<jupyter_output><empty_output><jupyter_text>Add up the wealth of all of the billionaires in a given country (or a few countries) and then compare it to the GDP of the country, or other billionaires, so like pit the US vs India What are the most common industries for billionaires to come from? What's the total amount of billionaire money from each industry?<jupyter_code>recent['sector'].value_counts().head(10)
df.groupby('sector')['networthusbillion'].sum()<jupyter_output><empty_output><jupyter_text>How many self made billionaires vs. others?<jupyter_code>(recent['selfmade'] == 'self-made').value_counts()<jupyter_output><empty_output><jupyter_text>How old are billionaires?<jupyter_code># recent['age'].value_counts().sort_values()
print("The average billionnaire is", round(recent['age'].mean()), "years old.")<jupyter_output>The average billionnaire is 63.0 years old.<jupyter_text>How old are billionaires self made vs. non self made?<jupyter_code>df.groupby('selfmade')['age'].mean()
 # or different industries?
df.groupby('sector')['age'].mean()
#youngest billionnaires 
recent.sort_values('age').head(10)
#oldest billionnaires 
recent.sort_values('age', ascending =False).head(10)
#Age distribution - maybe make a graph about it?

import matplotlib.pyplot as plt
%matplotlib inline
# This will scream we don't have matplotlib.
his = df['age'].hist(range=[0, 100])


his.set_title('Distribution of Age Amongst Billionaires')
his.set_xlabel('Age(years)')
his.set_ylabel('# of Billionnaires')
# Maybe just made a graph about how wealthy they are in general?
import matplotlib.pyplot as plt
%matplotlib inline
# This will scream we don't have matplotlib.


his = df['networthusbillion'].hist(range=[0, 45])


his.set_title('Distribution of Wealth Amongst Billionaires')
his.set_xlabel('Wealth(Billions)')
his.set_ylabel('# of Billionnaires')<jupyter_output><empty_output><jupyter_text>Maybe plot their net worth vs age (scatterplot)Make a bar graph of the top 10 or 20 richest<jupyter_code>recent.plot(kind='scatter', x='networthusbillion', y='age')
recent.plot(kind='scatter', x='age', y='networthusbillion', alpha = 0.2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13020427257133946, 'fraction_numerical': 0.025105254950881024, 'mean_word_length': 6.755743651753325, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '20008', 'license': 'MIT', 'n_tokens_mistral': 2201, 'n_tokens_neox': 1990, 'n_words': 607, 'path': '07/billionaires.ipynb', 'repo_name': 'M0nica/python-foundations-hw', 'size': '6413'}