Pandas Review…Again;)

Python Review Free Exercises — #PySeries#Episode 18

J3
Jungletronics
5 min readMar 20, 2021

--

Hi, answer these ten questions:

Pandas Exercises:)

Source of the Data:

The dataset will be valuable to those who seek to understand the dynamics of financial stability within the African context.ContentThe dataset specifically focuses on the Banking, Debt, Financial, Inflation and Systemic Crises that occurred, from 1860 to 2014, in 13 African countries, including: Algeria, Angola, Central African Republic, Ivory Coast, Egypt, Kenya, Mauritius, Morocco, Nigeria, South Africa, Tunisia, Zambia and Zimbabwe.* caseA number which denotes a specific country;* cc3A three letter country code;* country The name of the country;* year The year of the observation;* systemic_crisis “0” means that no systemic crisis occurred in the year and “1” means that a systemic crisis occurred in the year;* exch_usd The exchange rate of the country vis-a-vis the USD;* domestic_debt_in_default “0” means that no sovereign domestic debt default occurred in the year and “1” means that a sovereign domestic debt default occurred in the year;* sovereign_external_debt_default “0” means that no sovereign external debt default occurred in the year and “1” means that a sovereign external debt default occurred in the year;* gdp_weighted_default The total debt in default vis-a-vis the GDP;* inflation_annual_cpi The annual CPI Inflation rate;* independence “0” means “no independence” and “1” means “independence”;* currency_crises “0” means that no currency crisis occurred in the year and “1” means that a currency crisis occurred in the year;* inflation_crises “0” means that no inflation crisis occurred in the year and “1” means that an inflation crisis occurred in the year;* banking_crisis “no_crisis” means that no banking crisis occurred in the year and “crisis” means that a banking crisis occurred in the year;

Complete the ten Tasks Below:

01#PyEx — Python — Pandas— Importing:

Import pandas:

02#PyEx — Python — Pandas — IO:

Read in the african_econ_crises.csv:output expected:
# case cc3 country year systemic_crisis exch_usd domestic_debt_in_default sovereign_external_debt_default gdp_weighted_default inflation_annual_cpi independence currency_crises inflation_crises banking_crisis
#0 1 DZA Algeria 1870 1 0.052264 0 0 0.0 3.441456 0 0 0 crisis
#1 1 DZA Algeria 1871 0 0.052798 0 0 0.0 14.149140 0 0 0 no_crisis
#2 1 DZA Algeria 1872 0 0.052274 0 0 0.0 -3.718593 0 0 0 no_crisis
# …
Source of the Data:

03#PyEx — Python — Pandas — Data Set:

Display the first 5 rows of the data set:#output expected:
# case cc3 country year systemic_crisis exch_usd domestic_debt_in_default sovereign_external_debt_default gdp_weighted_default inflation_annual_cpi independence currency_crises inflation_crises banking_crisis
#0 1 DZA Algeria 1870 1 0.052264 0 0 0.0 3.441456 0 0 0 crisis
#1 1 DZA Algeria 1871 0 0.052798 0 0 0.0 14.149140 0 0 0 no_crisis
#2 1 DZA Algeria 1872 0 0.052274 0 0 0.0 -3.718593 0 0 0 no_crisis
#3 1 DZA Algeria 1873 0 0.051680 0 0 0.0 11.203897 0 0 0 no_crisis
#4 1 DZA Algeria 1874 0 0.051308 0 0 0.0 -3.848561 0 0 0 no_crisis

04#PyEx — Python — Pandas —Counting:

How many countries are present in this data set?#output expected: 13

05#PyEx — Python — Pandas —Data Set:

Which countries are present in this data set?#output expected:
array([‘Algeria’, ‘Angola’, ‘Central African Republic’, ‘Ivory Coast’,‘Egypt’, ‘Kenya’, ‘Mauritius’, ‘Morocco’, ‘Nigeria’,‘South Africa’, ‘Tunisia’, ‘Zambia’, ‘Zimbabwe’], dtype=object)

06#PyEx — Python — Pandas — Grouping:

Which country had the highest annual CPI Inflation rate? What was the inflation rate?#output expected:
# case cc3 country year systemic_crisis exch_usd domestic_debt_in_default sovereign_external_debt_default gdp_weighted_default inflation_annual_cpi independence currency_crises inflation_crises banking_crisis
#1053 70 ZWE Zimbabwe 2008 1 0.002 1 1 0.0 21989695.22 1 1 1 crisis

07#PyEx — Python — Pandas — Indexing & Slicing:

In what year did Kenya have its first sistemic crisis?#ouput expected:
# case cc3 country year systemic_crisis exch_usd domestic_debt_in_default sovereign_external_debt_default gdp_weighted_default inflation_annual_cpi independence currency_crises inflation_crises banking_crisis
#475 35 KEN Kenya 1985 1 16.2843 0 0 0.0 11.398 1 0 0 crisis

08#PyEx — Python — Pandas —Grouping:

How many yearly systemic crisises have occurred per country?#output expected
# country
# Algeria 4
# Angola 0
# Central African Republic 19
# Egypt 6
# Ivory Coast 4
# Kenya 13
# Mauritius 0
# Morocco 2
# Nigeria 10
# South Africa 0
# Tunisia 5
# Zambia 4
# Zimbabwe 15

09#PyEx — Python — Pandas —Grouuping:

How many years did a sovereign external debt default occur in Zimbabwe?#output expected:
#africa_data[africa_data.iloc[3]==’ZWE’]
#output expected: 30

10#PyEx — Python — Pandas — Indexing & Slicing:

In which year did Algeria have its highest exchange rate?#output expected:
#case cc3 country year systemic_crisis exch_usd domestic_debt_in_default sovereign_external_debt_default gdp_weighted_default inflation_annual_cpi independence currency_crises inflation_crises banking_crisis
#84 1 DZA Algeria 2014 0 87.970698 0 0 0.0 2.917 1 0 0 no_crisis

If you find this post helpful, please consider to subscribe to the Jungletronics for more posts like this.

Until next time!

I wish you excellent day!

Be safe!

Cheers!

Google Colab Notebooks are here:

Colab Notebook Anwers link:)

Google Drive link:)

Credits & References

INTRODUÇÃO A MACHINE LEARNING PARA CERTIFICAÇÃO HCIA-AI by crateus.ufc.br

https://www.huawei.com/en/

Posts Related:

00Episode#PySeries — Python — Jupiter Notebook Quick Start with VSCode — How to Set your Win10 Environment to use Jupiter Notebook

01Episode#PySeries — Python — Python 4 Engineers — Exercises! An overview of the Opportunities Offered by Python in Engineering!

02Episode#PySeries — Python — Geogebra Plus Linear Programming- We’ll Create a Geogebra program to help us with our linear programming

03Episode#PySeries — Python — Python 4 Engineers — More Exercises! — Another Round to Make Sure that Python is Really Amazing!

04Episode#PySeries — Python — Linear Regressions — The Basics — How to Understand Linear Regression Once and For All!

05Episode#PySeries — Python — NumPy Init & Python Review — A Crash Python Review & Initialization at NumPy lib.

06Episode#PySeries — Python — NumPy Arrays & Jupyter Notebook — Arithmetic Operations, Indexing & Slicing, and Conditional Selection w/ np arrays.

07Episode#PySeries — Python — Pandas — Intro & Series — What it is? How to use it?

08Episode#PySeries — Python — Pandas DataFrames — The primary Pandas data structure! It is a dict-like container for Series objects

09Episode#PySeries — Python — Python 4 Engineers — Even More Exercises! — More Practicing Coding Questions in Python!

10Episode#PySeries — Python — Pandas — Hierarchical Index & Cross-section — Open your Colab notebook and here are the follow-up exercises!

11Episode#PySeries — Python — Pandas — Missing Data — Let’s Continue the Python Exercises — Filling & Dropping Missing Data

12Episode#PySeries — Python — Pandas — Group By — Grouping large amounts of data and compute operations on these groups

13Episode#PySeries — Python — Pandas — Merging, Joining & Concatenations — Facilities For Easily Combining Together Series or DataFrame

14Episode#PySeries — Python — Pandas — Pandas Dataframe Examples: Column Operations

15Episode#PySeries — Python — Python 4 Engineers — Keeping It In The Short-Term Memory — Test Yourself! Coding in Python, Again!

16Episode#PySeries — NumPy — NumPy Review, Again;) — Python Review Free Exercises

17Episode#PySeries — Generators in Python — Python Review Free Hints

18pisode#PySeries — Pandas Review…Again;) — Python Review Free Exercise(this one)

19Episode#PySeriesMatlibPlot & Seaborn Python Libs — Reviewing theses Plotting & Statistics Packs

20Episode#PySeriesSeaborn Python Review — Reviewing theses Plotting & Statistics Packs

Img from https://towardsdatascience.com/python-pandas-data-frame-basics-b5cfbcd8c039

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!