8*6 2**16 2**\ 6 2**0.5 from numpy import sqrt sqrt(2) abs(-65) help(sqrt) SquareRoot2 = sqrt(2) SquareRoot2 HoursYear = 365*24 HoursYear dir()[:5] 'HoursYear' in dir() locals().keys()[:5] 'HoursYear' in locals().keys() import numpy as np np.array([2,3,5,8,13]) Country = np.array(["Brazil", "China", "India","Switzerland","USA"]) LifeExpectancy = np.array([74,76,65,83,79]) Country print Country print LifeExpectancy Country[0] LifeExpectancy[2] Sequence = np.arange(0,100+1,2) Sequence from pandas import DataFrame CountryData = DataFrame({'Country':Country, 'LifeExpectancy':LifeExpectancy}) print CountryData CountryData['Population'] = np.array([199000,1390000,1240000,7997,318000]) print CountryData Country = np.array(['Australia','Greece']) LifeExpectancy = np.array([82, 81]) Population = np.array([23050, 11125]) NewCountryData = DataFrame({'Country':Country, 'LifeExpectancy':LifeExpectancy, 'Population':Population}) print NewCountryData AllCountryData = CountryData.append(NewCountryData) print AllCountryData AllCountryData.index = range(len(AllCountryData)) print AllCountryData print CountryData.append(NewCountryData, True) import os path = 'C:\\Users\\iris\\documents\\github\\edX\\The Analytic Edge\\week1' os.chdir(path) import pandas as pd WHO = pd.read_csv("WHO.csv") WHO.head() print WHO.shape print WHO.dtypes print WHO.values.T[:,:5] WHO.describe(include = 'all') WHO_Europe = WHO[WHO.Region == "Europe"] WHO_Europe.shape WHO_Europe.to_csv("WHO_Europe.csv") del(WHO_Europe) WHO['Under15'].mean() WHO['Under15'].std() WHO['Under15'].describe() WHO['Under15'].idxmin() WHO['Country'][85] WHO['Under15'].idxmax() WHO.at[123,'Country'] WHO.plot('GNI', 'FertilityRate', kind = 'scatter') Outliers = WHO[(WHO.GNI > 10000) & (WHO.FertilityRate > 2.5)] Outliers.shape[0] Outliers[['Country','GNI','FertilityRate']] WHO.plot(y = 'CellularSubscribers', kind = 'hist', legend = False) WHO.boxplot('LifeExpectancy', by = 'Region') fig = plt.figure() WHO.boxplot('LifeExpectancy', by = 'Region', rot = 60) plt.title("Life Expectancy of Countries by Region") plt.suptitle("") plt.ylabel("Life Expectancy") WHO.groupby('Region').size() WHO.groupby('Region')['Over60'].mean() WHO.groupby('Region')['LiteracyRate'].min()