<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 What country are most billionaires from? For the top ones, how many billionaires per billion people?
Step1:  Who are the top 10 richest billionaires?
Step2:  What's the average wealth of a billionaire? Male? Female?
What's the average wealth of a billionaire? Male? Female
Step3:  Who is the poorest billionaire?
Step4:  Given the richest person in a country, what % of the GDP is their wealth?
Step5:  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?
Step6:  How many self made billionaires vs. others?
Step7:  How old are billionaires?
Step8:  How old are billionaires self made vs. non self made?
Step9:  Maybe plot their net worth vs age (scatterplot)
Make a bar graph of the top 10 or 20 richest
<ASSISTANT_TASK:>
Python 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)
Explanation: What country are most billionaires from? For the top ones, how many billionaires per billion people?
End of explanation
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()
Explanation: Who are the top 10 richest billionaires?
End of explanation
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")
Explanation: What's the average wealth of a billionaire? Male? Female?
What's the average wealth of a billionaire? Male? Female
End of explanation
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'
Explanation: Who is the poorest billionaire?
End of explanation
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
Explanation: Given the richest person in a country, what % of the GDP is their wealth?
End of explanation
recent['sector'].value_counts().head(10)
df.groupby('sector')['networthusbillion'].sum()
Explanation: 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?
End of explanation
(recent['selfmade'] == 'self-made').value_counts()
Explanation: How many self made billionaires vs. others?
End of explanation
# recent['age'].value_counts().sort_values()
print("The average billionnaire is", round(recent['age'].mean()), "years old.")
Explanation: How old are billionaires?
End of explanation
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')
Explanation: How old are billionaires self made vs. non self made?
End of explanation
recent.plot(kind='scatter', x='networthusbillion', y='age')
recent.plot(kind='scatter', x='age', y='networthusbillion', alpha = 0.2)
Explanation: Maybe plot their net worth vs age (scatterplot)
Make a bar graph of the top 10 or 20 richest
End of explanation
<END_TASK>