<jupyter_start><jupyter_text>Visualization<jupyter_code># Create scatter plot
plt.scatter(gdp_cap, life_exp)

# Put the x-axis on a logarithmic scale
plt.xscale('log')

# Show plot
plt.show()
#You can see that the higher GDP usually corresponds to a higher life expectancy. In other words, there is a positive correlation.

## But is there a relationship between population and life expectancy of a country?
# Build Scatter plot
plt.scatter(pop, life_exp)

# Show plot
plt.show()
# Basic scatter plot, log scale
plt.scatter(gdp_cap, life_exp)
plt.xscale('log') 

# Strings
xlab = 'GDP per Capita [in USD]'
ylab = 'Life Expectancy [in years]'
title = 'World Development from 1952-2007'

# Add axis labels
plt.xlabel(xlab)
plt.ylabel(ylab)

# Add title
plt.title(title)

# After customizing, display the plot
plt.show()
# Scatter plot

plt.scatter(gdp_cap, life_exp)

# Labels
plt.xscale('log') 
plt.xlabel('GDP per Capita [in USD]')
plt.ylabel('Life Expectancy [in years]')
plt.title('World GDP VS Life Expectancy ')

# Definition of tick_val and tick_lab
tick_val = [1000,10000,100000]
tick_lab = ['1k','10k','100k']

# Additional customizations to highlight China and India.
plt.text(2120, 65, 'India')
plt.text(4200, 74, 'China')

# Adapt the ticks on the x-axis
plt.xticks(tick_val, tick_lab)

#Add grid() call
plt.grid(True)

fig = plt.gcf()
fig.set_size_inches(10, 8)


# After customizing, display the plot
plt.show()
# customize the scatter plot to be more self explanatory 

# Store pop as a numpy array: np_pop
np_pop = np.array(pop)

# Double np_pop
np_pop = np_pop * 2
df = df_raw
is_2007 =  df['year']==2007
print(is_2007.head())
df_2007 = df[is_2007]
print(df_2007.shape)
print(df_2007.head())
pop_2007 = df_2007['population'].tolist()
gdpPercap = df_2007['gdpPerCap'].tolist()
lifeExp = df_2007['lifeExp'].tolist()
year_2007 = df_2007['year'].tolist()
pop = df_2007['population'].tolist()
pop[: 10]
# Create function that maps a country's continent to a color
def color_map(c):
 if c['continent'] == 'Asia':
  return 'red'
 elif c['continent'] == 'Europe':
  return 'green'
 elif c['continent'] == 'Africa':
  return 'blue'
 elif c['continent'] == 'Americas':
  return 'yellow'
 else:
  return 'black'
df_2007['color'] = df_2007.apply(color_map, axis=1)
df.head()
col = df_2007['color']
# Specify c and alpha inside plt.scatter()
plt.scatter(x = gdpPercap, y = lifeExp, c = col, alpha = 0.8)

# Labels
plt.xscale('log') 
plt.xlabel('GDP per Capita [in USD]')
plt.ylabel('Life Expectancy [in years]')
plt.title('World Development in 2007')

# Legend
blue_patch = mpatches.Patch(color='blue', label='Africa')
yellow_patch = mpatches.Patch(color='yellow', label='Americas')
red_patch = mpatches.Patch(color='red', label='Asia')
green_patch = mpatches.Patch(color='green', label='Europe')
black_patch = mpatches.Patch(color='black', label='Oceania')
plt.legend(handles=[blue_patch, yellow_patch, red_patch, green_patch, black_patch])

# Definition of tick_val and tick_lab
plt.xticks([1000,10000,100000], ['1k','10k','100k'])

# Show the plot
plt.show()
# Store pop as a numpy array: np_pop
np_pop = np.array(pop)

# Double np_pop
np_pop = np_pop * 2
# Scatter plot
plt.scatter(x = gdp_cap, y = life_exp,   c = col, alpha = 0.8)

# Labels
plt.xscale('log') 
plt.xlabel('GDP per Capita [in USD]')
plt.ylabel('Life Expectancy [in years]')
plt.title('Overview World Development in 1952 - 2007')

# Definition of tick_val and tick_lab
plt.xticks([1000,10000,100000], ['1k','10k','100k'])

# Legend
blue_patch = mpatches.Patch(color='blue', label='Africa')
yellow_patch = mpatches.Patch(color='yellow', label='Americas')
red_patch = mpatches.Patch(color='red', label='Asia')
green_patch = mpatches.Patch(color='green', label='Europe')
black_patch = mpatches.Patch(color='black', label='Oceania')
plt.legend(handles=[blue_patch, yellow_patch, red_patch, green_patch, black_patch])

# Additional customizations to highlight China and India.
plt.text(2120, 65, 'India')
plt.text(4200, 74, 'China')

#Add grid() call
plt.grid(True)

fig = plt.gcf()
fig.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Overview_World_Development_in_1952 _-_2007.png')

# Show the plot
plt.show()
df_2007_group = df[is_2007].groupby(['continent']).mean()
df_2007_group.head()
data= df_raw
data.tail(10)
# Assign variable
China = data[data.country == 'China']
# Plot GDP per Capita of China
plt.plot(China.year, China.gdpPerCap)
plt.title('GDP per Capita of China')
#Add grid() call
plt.grid(True)

fig1 = plt.gcf()
fig1.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/GDP_vs_Life_Expectancy_China.png')

plt.show()
# Plot GDP per Capita in United States

us = data[data.country == 'United States']
plt.plot(us.year, us.gdpPerCap)
plt.title('GDP per Capita of United States')
#Add grid() call
plt.grid(True)

fig2 = plt.gcf()
fig2.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/GDP_per_Capita_of_United_States.png')

plt.show()
# Plot Life expectancy in United States

us = data[data.country == 'United States']
plt.plot(us.year, us.lifeExp)
plt.title('Life expectancy in United States')

# Add grid() call
plt.grid(True)

fig3 = plt.gcf()
fig3.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/GDP_vs_Life_Expectancy_US.png')

plt.show()
# Plot Life expectancy in China
China = data[data.country == 'China']
plt.plot(China.year, China.lifeExp)
plt.title('Life expectancy in China')

# Add grid() call
plt.grid(True)

fig4 = plt.gcf()
fig4.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Life_Expectancy_China.png')

plt.show()<jupyter_output><empty_output><jupyter_text>Display a time series with line charts<jupyter_code># Assign variables
us = data[data.country == 'United States']
china = data[data.country == 'China']
# GDP per capita in China vs  United States
plt.plot(us.year, us.gdpPerCap)
plt.plot(china.year, china.gdpPerCap)
plt.legend(['United States', 'China'])
plt.xlabel('year')
plt.ylabel('GDP per capita [in years]')

plt.title('GDP in China vs  United States')
#Add grid() call
plt.grid(True)

fig5 = plt.gcf()
fig5.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/GDP_in_China _vs_United_States.png')

plt.show()
plt.plot(us.year, us.lifeExp)
plt.plot(china.year, china.lifeExp)
plt.legend(['United States', 'China'])
plt.xlabel('year')
plt.ylabel('Life expectancy ')
plt.title('Life Expectancy in China vs United States')

# Add grid() call
plt.grid(True)

fig6 = plt.gcf()
fig6.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Life_Expectancy_in_China_vs_United_States.png')

plt.show()

# Plot Life expectancy of China and US

plt.plot(us.year, us.lifeExp)

plt.plot(china.year, china.lifeExp)

plt.legend(['United States', 'china'])
plt.xlabel('year')
plt.ylabel('Life expectancy [in years]')

#Add grid() call
plt.grid(True)

fig7 = plt.gcf()
fig7.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Life_Expectancy_China_US.png')

plt.show()
##Find Distribution of Data using Histograms¶
set(data.continent)
# Assign variables 
data2007 = data[data.year == 2007]
asia2007 = data2007[data2007.continent == 'Asia']
europe2007 = data2007[data2007.continent == 'Europe']
len(set(asia2007.country))
len(set(europe2007.country))
asia2007.gdpPerCap.mean()
europe2007.gdpPerCap.mean()
asia2007.gdpPerCap.median()
europe2007.gdpPerCap.median()
#Comparing GDP of EU and Asia in 2007

plt.subplot(211)
plt.title('Comparing GDP of EU and Asia in 2007')
plt.hist(asia2007.gdpPerCap, 30, edgecolor='black')
plt.ylabel('Asia')
plt.subplot(212)
plt.hist(europe2007.gdpPerCap, 30, edgecolor='black')
plt.ylabel('Europe')
#Add grid() call
plt.grid(True)

fig8 = plt.gcf()
fig8.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Comparing_GDP_of_EU_and_Asia_in_2007.png')

plt.show()
# Top 10 countries with highest population

top10 = data2007.sort_values('population', ascending=False).head(10)
top10
# Plot the scatterplot for GDP per capita and life expectancy in 2007

plt.scatter(data2007.gdpPerCap, data2007.lifeExp)
plt.title('GDP per capita and life Expectancy in 2007')
plt.xlabel('GDP per capita [in USD]')
plt.ylabel('Life expectancy [in years]')

# Add grid() call
plt.grid(True)

fig9 = plt.gcf()
fig9.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/GDP_per_capita_and_life_Expectancy_in_2007.png')

plt.show()
# Sort data by year
yearsSorted = sorted(set(data.year))
# Plot scatter plots of GDP and life expectancy for every 5 years interval

for aYear in yearsSorted:
    dataYear = data[data.year == aYear]
    plt.scatter(dataYear.gdpPerCap, dataYear.lifeExp, 5)
    plt.title(aYear)
    plt.xlim(0,60000)
    plt.ylim(25, 85)
    plt.xlabel('GDP per capita [in USD]')
    plt.ylabel('Life expectancy [in years]')
    plt.show()

# Add grid() call
plt.grid(True)

fig11 = plt.gcf()
fig11.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/GDP_per_capita_and_Life_Expectancy.png')
# Group by continent

dfcontinent = df_raw.groupby(['continent']).median().head(5)
dfcontinent
# list of continents with associated average GDP

dfcontinent_gdp = dfcontinent['gdpPerCap']
dfcontinent_gdp
# Continents with the highest and lowest gdp 

continents = ['Africa','Americas','Asia','Europe','Oceania']
colors = [ "blue", "yellow", 'red','green', 'Black']
plt.bar(continents,dfcontinent_gdp, color= colors, alpha =.5, align ='center')

plt.xlabel("Continents")
plt.ylabel("gdp per cap [in USD]")
plt.title('Continents with the highest and lowest gdp')

# Add grid() call
plt.grid(True)

fig11 = plt.gcf()
fig11.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Continents_with_the_highest_and_lowest_gdp.png')
# Continents with Highest and Lowest Life Expectancy

continents = ['Africa','Americas','Asia','Europe','Oceania']
colors = [ "blue", "yellow", 'red','green', 'Black']

plt.bar(continents, dfcontinent['lifeExp'], color= colors, alpha =.5, align ='center')


plt.xlabel ("Continents")
plt.ylabel ("Life Expectancy [in years]")
plt.title("Continents with Highest and Lowest Life Expectancy")

# Add grid() call
plt.grid(True)

fig12 = plt.gcf()
fig12.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Continents_with_Highest_and_Lowest_Life_Expectancy.png')
# Continents with Highest and Lowest Population

continents = ['Africa','Americas','Asia','Europe','Oceania']
colors = [ "blue", "yellow", 'red','green', 'Black']
plt.bar(continents, dfcontinent['population'], color= colors, alpha =.5, align ='center')


plt.xlabel ("Continents")
plt.ylabel ("Population [in Billions]")
plt.title("Continents with Highest and Lowest Population")

# Add grid() call
plt.grid(True)

fig13 = plt.gcf()
fig13.set_size_inches(10, 8)

# Save the plot
#plt.savefig('./Images/Continents_with_Highest_and_Lowest_Population.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14997227869155424, 'fraction_numerical': 0.03871742746257623, 'mean_word_length': 5.705700123915737, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '501364', 'license': 'MIT', 'n_tokens_mistral': 4488, 'n_tokens_neox': 3967, 'n_words': 979, 'path': 'Analysis.ipynb', 'repo_name': 'v-hemanth/Data-Analysis-and-Visualization-on-Health-and-Wealth-of-Nations', 'size': '10822'}