<jupyter_start><jupyter_text>GDP Per Capita Analysis GDP per capita data was taken from world bankhttps://data.worldbank.org/indicator/NY.GDP.PCAP.CD<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>read "gdp_per_capita.csv" file into a dataframe<jupyter_code>data=pd.read_csv("gdp_per_capita_2020July.csv",skiprows=4)<jupyter_output><empty_output><jupyter_text>check the top-five rows the data frame<jupyter_code>data.head()
#set index of the dataframe as Country name
data.set_index("Country Name",inplace=True)
#check again top-five rows of the dataframe
data.head()<jupyter_output><empty_output><jupyter_text>How to delete a column?<jupyter_code># delete Country Code, Indicator Name and Indicator Code columns
data.drop(labels=["Country Code","Indicator Name","Indicator Code","Unnamed: 64"],axis="columns",inplace=True)
# check the dataframe
data.head()<jupyter_output><empty_output><jupyter_text>get data for Italy<jupyter_code>italy=data.loc["Italy"]
italy
type(italy)
# get italy's gdp per capita for 2019
italy["2019"]<jupyter_output><empty_output><jupyter_text>Find the year that italy has the highest increase of gdb per capita  - Calculate the yearly percentage increase compared to previous year - find the year that has highest increase in terms of percentage.<jupyter_code>italy<jupyter_output><empty_output><jupyter_text>calculate the yearly change in percentage<jupyter_code>italy_pct_change=italy.pct_change()
# multiply italy_pct_change by 100
italy_pct_change=italy_pct_change*100
italy_pct_change<jupyter_output><empty_output><jupyter_text>find the year that has highest change<jupyter_code>italy_pct_change.idxmax()<jupyter_output><empty_output><jupyter_text>Find the years that GDP per capita decreased compared to the previous year.<jupyter_code>italy_negative=italy_pct_change[italy_pct_change>0]
# get only years
italy_negative.index<jupyter_output><empty_output><jupyter_text>Find the year that GDP per capita of the world increased the most compared to previous year<jupyter_code>data.head()
# first get the data for world
# there is an index named World
world=data.loc["World"]
# now find the year that has highest increase in percentange
world.pct_change().idxmax()<jupyter_output><empty_output><jupyter_text>find top 10 years that have highest standart deviation<jupyter_code># first calculate standart deviation for each year
data_std=data.std()
data_std
# now top-10 years having the hightest standart deviation
data_std.nlargest(10)<jupyter_output><empty_output><jupyter_text>Which country has the highest gdp_per_capita in 2019?<jupyter_code>data.head()
# get the data for the year 2019
data_2019=data["2019"]
data_2019
# now get the country
data_2019.idxmax()
data_2019.nlargest(1)<jupyter_output><empty_output><jupyter_text>Rank of Luxembourg find the rank of Luxembourg each year<jupyter_code># calculate the rank of each country for each year
data_rank=data.rank(ascending=False)
data_rank
# now get the rank of Luxembourg
lux_rank=data_rank.loc["Luxembourg"]
lux_rank
# plot the rank of luxembourg
lux_rank.plot()
# print the years where Luxembourg ranks top
lux_rank[lux_rank==1]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08716173694147263, 'fraction_numerical': 0.01825047199496539, 'mean_word_length': 8.604229607250755, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 54, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '493491', 'license': 'Unlicense', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1072, 'n_words': 275, 'path': 'Data Analysis with Python/pandas_workshop-master/gdp_per_capita/gdp_per_capita_solutions.ipynb', 'repo_name': 'larandrup/larandrup.github.io', 'size': '3178'}