In [29]:
import pandas as pd
import csv
import matplotlib.pyplot as plt
READING CSV: I want to read the csv using the Pandas '.read_csv' which returns a DataFrame Object.
In [42]:
income_df = pd.read_csv('LifeExpectancyIncome.csv')
In [43]:
income_df
Out[43]:
I have a few things to do, first i want to flip the positions of columns with the of row index variables.
I've chosen to use the transpose function, which causes the columns and index to change places.
In [44]:
income_df = income_df.set_index('Country').transpose()
In [45]:
income_df
Out[45]:
I would like to remove any characters that do not represent number values and return these as intergers.
In [46]:
income_df['Income / Person'] = income_df['Income / Person'].str.replace(r'[^-+\d.]', '').astype(int)
In [47]:
income_df['Life Expectancy'] = income_df['Life Expectancy'].astype(int)
In [53]:
income_df
Out[53]:
In [54]:
income_df.plot(kind='area')
Out[54]:
In [55]:
plt.show()
In [18]:
income_df.plot(kind='bar', title='Income vs Life Expectancy')
Out[18]:
In [19]:
plt.show() #bar graph
In [ ]:
income_df.plot(x = 'Income / Person',y='Life Expectancy', kind='scatter')
In [ ]:
plt.show() #scatter chart
In [61]:
plt.figure(figsize=(9, 6))
Out[61]:
In [62]:
income_df = income_df.drop('Ethiopia')
In [68]:
income_df.plot(x='Income / Person', y='Life Expectancy', kind='bar', stacked=True)
Out[68]:
In [ ]:
plt.show()
In [24]:
protein_df = pd.read_csv('HighProteinFoods.csv')
In [25]:
protein_df.stack()
Out[25]:
In [ ]:
In [ ]: