<jupyter_start><jupyter_text>BILLIONAIRES Let us first import the database.<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_excel("richpeople.xlsx")
rich = df[df['year'] == 2014] #Getting only the latest list.
rich.head(5)
rich.columns<jupyter_output><empty_output><jupyter_text>What country are most billionaires from? For the top ones, how many billionaires per billion people?<jupyter_code>numberofbillionaires=rich['countrycode'].value_counts() #Clearly, Americans lead. 
numberofbillionaires.head(10)
numberofbillionairesperbillionpeople=numberofbillionaires/1000000000
numberofbillionairesperbillionpeople.head(6)<jupyter_output><empty_output><jupyter_text>Who are the top 10 richest billionaires?<jupyter_code>sortedrich=rich.sort_values(by='networthusbillion',ascending=False)
sortedrich.head(10)<jupyter_output><empty_output><jupyter_text>Who is the poorest billionaire? Who are the top 10 poorest billionaires?<jupyter_code>sortedpoor=rich.sort_values(by='networthusbillion')
sortedpoor.head(10)<jupyter_output><empty_output><jupyter_text>'What is relationship to company'? And what are the most common relationships?<jupyter_code>rich['relationshiptocompany'].head(5)<jupyter_output><empty_output><jupyter_text>It is how the millionaire is related to the company in the industry from which they made the billions.<jupyter_code>relations=rich['relationshiptocompany'].value_counts()
relations.head(10) #The problem with the dataset is a little apparent now. 
#CEO and ceo are seen differently. Chairman AND Ceo is one category, either of those are separate categories.
#One can replace ceo with CEO and see how things change.
rich1=rich.replace(['ceo'],['CEO'])
relations=rich1['relationshiptocompany'].value_counts()
relations.head(10) #The newer version of rich has CEOs merged into one list. So CEO is sixth most common position after investor.<jupyter_output><empty_output><jupyter_text>Most common source of wealth? Male vs. female?<jupyter_code>source=rich1['sourceofwealth'].value_counts()
source.head(10) #REAL ESTATE IS WHERE THE MONEY IS, GUYS! "Diversified", HAHA!
maleb=rich1[rich1['gender']=='male']
maleb['sourceofwealth'].value_counts()

femaleb=rich1[rich1['gender']=='female']
femaleb['sourceofwealth'].value_counts()

rich1['gender'].value_counts() #Inherent Patriarchy perhaps<jupyter_output><empty_output><jupyter_text>Given the richest person in a country, what % of the GDP is their wealth?<jupyter_code>gdp_csv=pd.read_csv('http://data.okfn.org/data/core/gdp/r/gdp.csv')
gdp_2014 = gdp_csv[gdp_csv['Year'] == 2014]
gdp_2014.tail()
gdp_2014=gdp_2014.rename(columns={'Country Code': 'countrycode'})
gdp_2014.tail()
rich2=pd.merge(rich1, gdp_2014, on='countrycode', how='outer')
rich2['percentageofcountrygdptheirwealthis']=(rich2['networthusbillion'])/(rich2['Value'])
rich2['percentageofcountrygdptheirwealthis'].head()<jupyter_output><empty_output><jupyter_text>What's the average wealth of a billionaire? Male? Female?<jupyter_code>df['networthusbillion'].describe()
maleb['networthusbillion'].describe()
femaleb['networthusbillion'].describe()<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<jupyter_code>americanbillionaires=rich2[rich2['countrycode']=='USA']
indianbillionaires=rich2[rich2['countrycode']=='IND']
wealthofamerica=americanbillionaires['networthusbillion'].sum()
wealthofamerica
wealthofindia=indianbillionaires['networthusbillion'].sum()
wealthofindia<jupyter_output><empty_output><jupyter_text>What are the most common industries for billionaires to come from? What's the total amount of billionaire money from each industry?<jupyter_code>rich2['industry'].value_counts()<jupyter_output><empty_output><jupyter_text>How many self made billionaires vs. others?<jupyter_code>rich2['selfmade'].value_counts()<jupyter_output><empty_output><jupyter_text>How old are billionaires? How old are billionaires self made vs. non self made? or different industries?<jupyter_code>selfmade=rich2[rich2['selfmade']=='self-made']
nonselfmade=rich2[rich2['selfmade']=='inherited']
print("The values for self made billionaires")
selfmade['age'].value_counts()
selfmade['age'].hist()
print("The values for non-self made billionaires")
nonselfmade['age'].value_counts()
nonselfmade['age'].hist(label='Self Made Billionaires Age vs Number')
rich2['age'].value_counts()<jupyter_output><empty_output><jupyter_text>Who are the youngest billionaires? The oldest?<jupyter_code>rich2.sort_values(by='age').head(10)
rich2.sort_values(by='age',ascending=False).head(10)<jupyter_output><empty_output><jupyter_text>Maybe plot their net worth vs age (scatterplot)<jupyter_code>rich2.plot(kind='scatter',x='age',y='networthusbillion')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12219959266802444, 'fraction_numerical': 0.018940936863543787, 'mean_word_length': 10.528169014084508, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '226532', 'license': 'MIT', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1602, 'n_words': 343, 'path': '07/07 Homework Part 2.ipynb', 'repo_name': 'HarshaDevulapalli/foundations-homework', 'size': '4910'}