import pandas as pd

!pip install pandas

df = pd.read_excel("Billionaire Characteristics Database/richpeople.xlsx")

!pip install xlrd

df.head(1)

df.columns

recent = df[df['year'] == 2014]
recent.head(1)

"""
Explanation: The Richest People in the World: Taking a closer look at Switzerland and the Gender Gap
End of explanation
"""


recent['countrycode'].value_counts().head()
#df['animal'].value_counts()

"""
Explanation: 1) Where are most billionaires from?
End of explanation
"""


Swiss_billionaires = recent[recent['countrycode'] == 'CHE']
Swiss_billionaires.count().head(1)

"""
Explanation: 2) How many of them are from Switzerland?
End of explanation
"""


Swiss_billionaires = recent[recent['countrycode'] == 'CHE']
Swiss_billionaires_sorted = Swiss_billionaires.sort_values(by='networthusbillion', ascending=False)
Swiss_billionaires_sorted


"""
Explanation: 3) Display all of the Swiss billionaires, starting with the richest.
End of explanation
"""


female_Swiss_billionaires = Swiss_billionaires[Swiss_billionaires['gender'] == 'female'].count().head(1)
female_Swiss_billionaires

male_Swiss_billionaire = Swiss_billionaires[Swiss_billionaires['gender'] == 'male'].count().head(1)
male_Swiss_billionaire

"""
Explanation: 4) How many of the richest Swiss are female, and how many are male?
End of explanation
"""


female_Swiss_billionaires_list = Swiss_billionaires[Swiss_billionaires['gender'] == 'female']
female_mean = female_Swiss_billionaires_list['networthusbillion'].mean()
print(female_mean)

#print("Swiss female billionaire's average wealth:", female_Swiss_billionaire['networthusbillion'].mean())
#print("Swiss male billionaire's average wealth:", male_Swiss_billionaire['networthusbillion'].mean())

male_Swiss_billionaires_list = Swiss_billionaires[Swiss_billionaires['gender'] == 'male']
male_mean = male_Swiss_billionaires_list['networthusbillion'].mean()
print(male_mean)

diff = male_mean - female_mean
Millions_diff = diff * 1000
male_sum = male_Swiss_billionaires_list['networthusbillion'].sum()
female_sum = female_Swiss_billionaires_list['networthusbillion'].sum()

print("In total Swiss male billionaires have funds of", male_sum, "billion US-Dollars. Female billionaires own", female_sum,"billion meaning that in average a Swiss male billionaire has", Millions_diff, "million USD more than Swiss female billionaires. That's qite a bit of cash!")

"""
Explanation: So that is 8 female Swiss billionaires and 14 male ones.
5) How is their wealth distributed? How many billions do super rich men and women have in Switzerland compared to women?
End of explanation
"""


#df[(df['animal'] == 'cat') & (df['inches'] > 12)]
male_Swiss_billionaires_list[male_Swiss_billionaires_list['selfmade'] == 'inherited'].count().head(1)
inherited = male_Swiss_billionaires_list[male_Swiss_billionaires_list['selfmade'] == 'inherited'].count().head(1)
print("So out of 14 male Swiss billionaires 9 of them inherited their fortune.")


female_Swiss_billionaires_list[female_Swiss_billionaires_list['selfmade'] == 'inherited'].count().head(1)
female_inherited = female_Swiss_billionaires_list[female_Swiss_billionaires_list['selfmade'] == 'inherited'].count().head()
female_inherited
#print("Out of 8 Swiss female billionaires, only one woman made her fortune on her own")

"""
Explanation: 6) Do more Swiss women or more men inherit their fortunes?
End of explanation
"""


recent[(recent['gender'] == 'female') & (recent['selfmade'] == 'self-made') & (recent['countrycode'] == 'CHE')]

"""
Explanation: 7) Display the only Swiss female billionaire who is a self made woman?
End of explanation
"""


recent[(recent['gender'] == 'female')].sort_values(by='networthusbillion', ascending=False)

"""
Explanation: 8) Display the richest woman in the world
End of explanation
"""


recent[(recent['gender'] == 'female') & (recent['selfmade'] == 'self-made')].sort_values(by='networthusbillion', ascending=False)

"""
Explanation: 9) Who is the richest self made woman? And how many women are selfmade?
End of explanation
"""


recent[(recent['gender'] == 'male') & (recent['selfmade'] == 'self-made')].sort_values(by='networthusbillion', ascending=False)

"""
Explanation: Interesting. Chan Laiwa, the richest self made woman in the world is from China. She is also above 70. The second on the list, Gayle Cook, is even over 80.
10. Lets compare that to the richest self made men. How much have they made?
End of explanation
"""


recent.sort_values(by='age').head(5)

"""
Explanation: 11. What about the youngest billionaires. Are any of them female?
End of explanation
"""


female_billionaires = recent[recent['gender'] == 'female']
male_billionaires = recent[recent['gender'] == 'male']
print("Female billionaire average wealth:", female_billionaires['networthusbillion'].mean())
print("Male billionaire average wealth:", male_billionaires['networthusbillion'].mean())

females = female_billionaires['networthusbillion'].mean()
males = male_billionaires['networthusbillion'].mean()
difference = ((float(females) - float(males)) * 1000000000)
females_more_than_males = int(difference) / 1000000

print("Female billionaires are slighthly richer than their mail counterparts. In average they have", int(females_more_than_males), "Million US-Dollars more than men." )

total_billions_women = int(female_billionaires['networthusbillion'].sum())

total_billions_men = int(male_billionaires['networthusbillion'].sum())

print("In total, however, male billions have", int(total_billions_men / total_billions_women), "times more billions than women. In total:",total_billions_men, "billion US-Dollars. That is more than the GDP of France.")

"""
Explanation: 12. We compared women's and men's average fortunes before for Switzerland. Lets do the same for the whole world.
End of explanation
"""


recent.sort_values(by='networthusbillion', ascending = False).head(5)

"""
Explanation: 13.  Who has the most billions?
End of explanation
"""


recent.groupby(['countrycode'])['networthusbillion'].mean().sort_values(ascending = False).head(15)

"""
Explanation: 14. Which nation has the wealthiest billionaires in average?
End of explanation
"""


%matplotlib inline

import matplotlib.pyplot as plt
plt.style.available
plt.style.use('fivethirtyeight')

recent.plot(kind='scatter', x='age', y='networthusbillion')
plt.savefig("Scatterplot_billionaires_worldwide.svg")

"""
Explanation: 15. How is the wealth distributed by age? Lets plot that out.
End of explanation
"""


