Browsing Tag

# export ## Data visualization with Python and Matplotlib – Part 2

In the previous chapter I described how to import the needed data to Pandas DataFrames, and how to manipulate DataFrame object. Now lets take a look on how we can visualize that data in a plot form. This is by no means a proper analysis of the suicide rates. It is a plotting example.
Below are the necessary imports. ‘%matplotlib inline’ is IPython-specific directive which displays matplotlib plots in notebook. It can be removed and plt.show() can be added to the end of the code to display the plot. We are also importing numpy, pandas, matplotlib.pyplot for plotting, and separately matplotlib to work on specific matplotlib functions if needed.

In :
```%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
```

Next step is to import our data and assign it to DataFrame. We created that table in the previous example.

In :
```table = pd.read_excel('mergedData.xlsx')
```
Out:
Country 2015_s 2010_s 2015_p 2013_p 2010_p 2013_d suiAve suiPerDeath deaPerPop
0 Afghanistan 5.5 5.2 32526.6 30682.5 27962.2 7.7 5.35 0.694805 0.77
1 Albania 4.3 5.3 2896.7 2883.3 2901.9 9.4 4.80 0.510638 0.94
2 Algeria 3.1 3.4 39666.5 38186.1 36036.2 5.7 3.25 0.570175 0.57
3 Angola 20.5 20.7 25022.0 23448.2 21220.0 13.9 20.60 1.482014 1.39
4 Antigua and Barbuda 0.0 0.2 91.8 90.0 87.2 6.8 0.10 0.014706 0.68 ## Data import with Python, using pandas DataFrame – Part 1

World Health Organization provides a wide range of data available for download in different formats.
The data is accessible through their website: http://www.who.int/gho/en/
In this example we will be working with Pandas DataFrame to organize the data. As an example I am going to work on suicide rates throughout the world.

In :
```import pandas as pd
```

By using ‘read_csv’ function, suicide crude rates (per 100,000 people) data is assigned to pandas object.

In :
```suicideData = pd.read_csv('SuicBoth.csv')
{"ft_lang_label":"__label__en","ft_lang_prob":0.81054854,"math_prob":0.8076701,"size":926,"snap":"2019-26-2019-30","text_gpt3_token_len":191,"char_repetition_ratio":0.14859003,"word_repetition_ratio":0.0,"special_character_ratio":0.19978401,"punctuation_ratio":0.11235955,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95404357,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,4,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-19T06:15:16Z\",\"WARC-Record-ID\":\"<urn:uuid:86a9ce0d-46ba-4ed0-b8e4-b3df62a6c0a9>\",\"Content-Length\":\"36517\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0aaa7cee-854d-464f-b7f3-6bf9b1007697>\",\"WARC-Concurrent-To\":\"<urn:uuid:da9280a4-f39a-42f4-8ddf-0b4ea96ff4e1>\",\"WARC-IP-Address\":\"173.201.97.1\",\"WARC-Target-URI\":\"http://codewithmax.com/tag/export/\",\"WARC-Payload-Digest\":\"sha1:LS2CANLT4H54T44ISNUTR7E7PO4MFHAG\",\"WARC-Block-Digest\":\"sha1:5PWSNGYNSGNTHDPPA3UDQU2UL3SEP5M6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195526064.11_warc_CC-MAIN-20190719053856-20190719075856-00282.warc.gz\"}"}