import math
print('pi is', math.pi)
print('cos(pi) is', math.cos(math.pi))
pi is 3.141592653589793 cos(pi) is -1.0
help(math)
Help on module math:
NAME
math
MODULE REFERENCE
http://docs.python.org/3.5/library/math
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
DESCRIPTION
This module is always available. It provides access to the
mathematical functions defined by the C standard.
FUNCTIONS
acos(...)
acos(x)
Return the arc cosine (measured in radians) of x.
acosh(...)
acosh(x)
Return the inverse hyperbolic cosine of x.
asin(...)
asin(x)
Return the arc sine (measured in radians) of x.
asinh(...)
asinh(x)
Return the inverse hyperbolic sine of x.
atan(...)
atan(x)
Return the arc tangent (measured in radians) of x.
atan2(...)
atan2(y, x)
Return the arc tangent (measured in radians) of y/x.
Unlike atan(y/x), the signs of both x and y are considered.
atanh(...)
atanh(x)
Return the inverse hyperbolic tangent of x.
ceil(...)
ceil(x)
Return the ceiling of x as an int.
This is the smallest integral value >= x.
copysign(...)
copysign(x, y)
Return a float with the magnitude (absolute value) of x but the sign
of y. On platforms that support signed zeros, copysign(1.0, -0.0)
returns -1.0.
cos(...)
cos(x)
Return the cosine of x (measured in radians).
cosh(...)
cosh(x)
Return the hyperbolic cosine of x.
degrees(...)
degrees(x)
Convert angle x from radians to degrees.
erf(...)
erf(x)
Error function at x.
erfc(...)
erfc(x)
Complementary error function at x.
exp(...)
exp(x)
Return e raised to the power of x.
expm1(...)
expm1(x)
Return exp(x)-1.
This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
fabs(...)
fabs(x)
Return the absolute value of the float x.
factorial(...)
factorial(x) -> Integral
Find x!. Raise a ValueError if x is negative or non-integral.
floor(...)
floor(x)
Return the floor of x as an int.
This is the largest integral value <= x.
fmod(...)
fmod(x, y)
Return fmod(x, y), according to platform C. x % y may differ.
frexp(...)
frexp(x)
Return the mantissa and exponent of x, as pair (m, e).
m is a float and e is an int, such that x = m * 2.**e.
If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
fsum(...)
fsum(iterable)
Return an accurate floating point sum of values in the iterable.
Assumes IEEE-754 floating point arithmetic.
gamma(...)
gamma(x)
Gamma function at x.
gcd(...)
gcd(x, y) -> int
greatest common divisor of x and y
hypot(...)
hypot(x, y)
Return the Euclidean distance, sqrt(x*x + y*y).
isclose(...)
is_close(a, b, *, rel_tol=1e-09, abs_tol=0.0) -> bool
Determine whether two floating point numbers are close in value.
rel_tol
maximum difference for being considered "close", relative to the
magnitude of the input values
abs_tol
maximum difference for being considered "close", regardless of the
magnitude of the input values
Return True if a is close in value to b, and False otherwise.
For the values to be considered close, the difference between them
must be smaller than at least one of the tolerances.
-inf, inf and NaN behave similarly to the IEEE 754 Standard. That
is, NaN is not close to anything, even itself. inf and -inf are
only close to themselves.
isfinite(...)
isfinite(x) -> bool
Return True if x is neither an infinity nor a NaN, and False otherwise.
isinf(...)
isinf(x) -> bool
Return True if x is a positive or negative infinity, and False otherwise.
isnan(...)
isnan(x) -> bool
Return True if x is a NaN (not a number), and False otherwise.
ldexp(...)
ldexp(x, i)
Return x * (2**i).
lgamma(...)
lgamma(x)
Natural logarithm of absolute value of Gamma function at x.
log(...)
log(x[, base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
log10(...)
log10(x)
Return the base 10 logarithm of x.
log1p(...)
log1p(x)
Return the natural logarithm of 1+x (base e).
The result is computed in a way which is accurate for x near zero.
log2(...)
log2(x)
Return the base 2 logarithm of x.
modf(...)
modf(x)
Return the fractional and integer parts of x. Both results carry the sign
of x and are floats.
pow(...)
pow(x, y)
Return x**y (x to the power of y).
radians(...)
radians(x)
Convert angle x from degrees to radians.
sin(...)
sin(x)
Return the sine of x (measured in radians).
sinh(...)
sinh(x)
Return the hyperbolic sine of x.
sqrt(...)
sqrt(x)
Return the square root of x.
tan(...)
tan(x)
Return the tangent of x (measured in radians).
tanh(...)
tanh(x)
Return the hyperbolic tangent of x.
trunc(...)
trunc(x:Real) -> Integral
Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.
DATA
e = 2.718281828459045
inf = inf
nan = nan
pi = 3.141592653589793
FILE
/Users/jtdennis/anaconda/envs/py35/lib/python3.5/lib-dynload/math.so
from math import cos, pi
print('cos(pi) is', cos(pi))
cos(pi) is -1.0
import math as m
print('cos(pi) is', m.cos(m.pi))
cos(pi) is -1.0
import pandas
!ls data
gapminder_all.csv gapminder_gdp_americas.csv gapminder_gdp_europe.csv gapminder_gdp_africa.csv gapminder_gdp_asia.csv gapminder_gdp_oceania.csv
data = pandas.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
data.info()
<class 'pandas.core.frame.DataFrame'> Index: 2 entries, Australia to New Zealand Data columns (total 12 columns): gdpPercap_1952 2 non-null float64 gdpPercap_1957 2 non-null float64 gdpPercap_1962 2 non-null float64 gdpPercap_1967 2 non-null float64 gdpPercap_1972 2 non-null float64 gdpPercap_1977 2 non-null float64 gdpPercap_1982 2 non-null float64 gdpPercap_1987 2 non-null float64 gdpPercap_1992 2 non-null float64 gdpPercap_1997 2 non-null float64 gdpPercap_2002 2 non-null float64 gdpPercap_2007 2 non-null float64 dtypes: float64(12) memory usage: 208.0+ bytes
print(data.columns)
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
dtype='object')
print(data.T)
country Australia New Zealand gdpPercap_1952 10039.59564 10556.57566 gdpPercap_1957 10949.64959 12247.39532 gdpPercap_1962 12217.22686 13175.67800 gdpPercap_1967 14526.12465 14463.91893 gdpPercap_1972 16788.62948 16046.03728 gdpPercap_1977 18334.19751 16233.71770 gdpPercap_1982 19477.00928 17632.41040 gdpPercap_1987 21888.88903 19007.19129 gdpPercap_1992 23424.76683 18363.32494 gdpPercap_1997 26997.93657 21050.41377 gdpPercap_2002 30687.75473 23189.80135 gdpPercap_2007 34435.36744 25185.00911
print(data)
gdpPercap_1952 gdpPercap_1957 gdpPercap_1962 gdpPercap_1967 \
country
Australia 10039.59564 10949.64959 12217.22686 14526.12465
New Zealand 10556.57566 12247.39532 13175.67800 14463.91893
gdpPercap_1972 gdpPercap_1977 gdpPercap_1982 gdpPercap_1987 \
country
Australia 16788.62948 18334.19751 19477.00928 21888.88903
New Zealand 16046.03728 16233.71770 17632.41040 19007.19129
gdpPercap_1992 gdpPercap_1997 gdpPercap_2002 gdpPercap_2007
country
Australia 23424.76683 26997.93657 30687.75473 34435.36744
New Zealand 18363.32494 21050.41377 23189.80135 25185.00911
print(data.describe())
gdpPercap_1952 gdpPercap_1957 gdpPercap_1962 gdpPercap_1967 \
count 2.000000 2.000000 2.000000 2.000000
mean 10298.085650 11598.522455 12696.452430 14495.021790
std 365.560078 917.644806 677.727301 43.986086
min 10039.595640 10949.649590 12217.226860 14463.918930
25% 10168.840645 11274.086022 12456.839645 14479.470360
50% 10298.085650 11598.522455 12696.452430 14495.021790
75% 10427.330655 11922.958888 12936.065215 14510.573220
max 10556.575660 12247.395320 13175.678000 14526.124650
gdpPercap_1972 gdpPercap_1977 gdpPercap_1982 gdpPercap_1987 \
count 2.00000 2.000000 2.000000 2.000000
mean 16417.33338 17283.957605 18554.709840 20448.040160
std 525.09198 1485.263517 1304.328377 2037.668013
min 16046.03728 16233.717700 17632.410400 19007.191290
25% 16231.68533 16758.837652 18093.560120 19727.615725
50% 16417.33338 17283.957605 18554.709840 20448.040160
75% 16602.98143 17809.077557 19015.859560 21168.464595
max 16788.62948 18334.197510 19477.009280 21888.889030
gdpPercap_1992 gdpPercap_1997 gdpPercap_2002 gdpPercap_2007
count 2.000000 2.000000 2.000000 2.000000
mean 20894.045885 24024.175170 26938.778040 29810.188275
std 3578.979883 4205.533703 5301.853680 6540.991104
min 18363.324940 21050.413770 23189.801350 25185.009110
25% 19628.685413 22537.294470 25064.289695 27497.598692
50% 20894.045885 24024.175170 26938.778040 29810.188275
75% 22159.406358 25511.055870 28813.266385 32122.777857
max 23424.766830 26997.936570 30687.754730 34435.367440
data.info()
<class 'pandas.core.frame.DataFrame'> Index: 2 entries, Australia to New Zealand Data columns (total 12 columns): gdpPercap_1952 2 non-null float64 gdpPercap_1957 2 non-null float64 gdpPercap_1962 2 non-null float64 gdpPercap_1967 2 non-null float64 gdpPercap_1972 2 non-null float64 gdpPercap_1977 2 non-null float64 gdpPercap_1982 2 non-null float64 gdpPercap_1987 2 non-null float64 gdpPercap_1992 2 non-null float64 gdpPercap_1997 2 non-null float64 gdpPercap_2002 2 non-null float64 gdpPercap_2007 2 non-null float64 dtypes: float64(12) memory usage: 208.0+ bytes
data.columns
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
dtype='object')
print(data.T)
country Australia New Zealand gdpPercap_1952 10039.59564 10556.57566 gdpPercap_1957 10949.64959 12247.39532 gdpPercap_1962 12217.22686 13175.67800 gdpPercap_1967 14526.12465 14463.91893 gdpPercap_1972 16788.62948 16046.03728 gdpPercap_1977 18334.19751 16233.71770 gdpPercap_1982 19477.00928 17632.41040 gdpPercap_1987 21888.88903 19007.19129 gdpPercap_1992 23424.76683 18363.32494 gdpPercap_1997 26997.93657 21050.41377 gdpPercap_2002 30687.75473 23189.80135 gdpPercap_2007 34435.36744 25185.00911
data.describe()
| gdpPercap_1952 | gdpPercap_1957 | gdpPercap_1962 | gdpPercap_1967 | gdpPercap_1972 | gdpPercap_1977 | gdpPercap_1982 | gdpPercap_1987 | gdpPercap_1992 | gdpPercap_1997 | gdpPercap_2002 | gdpPercap_2007 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.00000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 |
| mean | 10298.085650 | 11598.522455 | 12696.452430 | 14495.021790 | 16417.33338 | 17283.957605 | 18554.709840 | 20448.040160 | 20894.045885 | 24024.175170 | 26938.778040 | 29810.188275 |
| std | 365.560078 | 917.644806 | 677.727301 | 43.986086 | 525.09198 | 1485.263517 | 1304.328377 | 2037.668013 | 3578.979883 | 4205.533703 | 5301.853680 | 6540.991104 |
| min | 10039.595640 | 10949.649590 | 12217.226860 | 14463.918930 | 16046.03728 | 16233.717700 | 17632.410400 | 19007.191290 | 18363.324940 | 21050.413770 | 23189.801350 | 25185.009110 |
| 25% | 10168.840645 | 11274.086022 | 12456.839645 | 14479.470360 | 16231.68533 | 16758.837652 | 18093.560120 | 19727.615725 | 19628.685413 | 22537.294470 | 25064.289695 | 27497.598692 |
| 50% | 10298.085650 | 11598.522455 | 12696.452430 | 14495.021790 | 16417.33338 | 17283.957605 | 18554.709840 | 20448.040160 | 20894.045885 | 24024.175170 | 26938.778040 | 29810.188275 |
| 75% | 10427.330655 | 11922.958888 | 12936.065215 | 14510.573220 | 16602.98143 | 17809.077557 | 19015.859560 | 21168.464595 | 22159.406358 | 25511.055870 | 28813.266385 | 32122.777857 |
| max | 10556.575660 | 12247.395320 | 13175.678000 | 14526.124650 | 16788.62948 | 18334.197510 | 19477.009280 | 21888.889030 | 23424.766830 | 26997.936570 | 30687.754730 | 34435.367440 |
data = pandas.read_csv('data/gapminder_gdp_europe.csv', index_col='country')
print(data.ix["Albania", "gdpPercap_1952"])
1601.056136
print(data.ix[0,0])
1601.056136
print(data.ix["Albania", :])
gdpPercap_1952 1601.056136 gdpPercap_1957 1942.284244 gdpPercap_1962 2312.888958 gdpPercap_1967 2760.196931 gdpPercap_1972 3313.422188 gdpPercap_1977 3533.003910 gdpPercap_1982 3630.880722 gdpPercap_1987 3738.932735 gdpPercap_1992 2497.437901 gdpPercap_1997 3193.054604 gdpPercap_2002 4604.211737 gdpPercap_2007 5937.029526 Name: Albania, dtype: float64
data.ix["Albania"]
gdpPercap_1952 1601.056136 gdpPercap_1957 1942.284244 gdpPercap_1962 2312.888958 gdpPercap_1967 2760.196931 gdpPercap_1972 3313.422188 gdpPercap_1977 3533.003910 gdpPercap_1982 3630.880722 gdpPercap_1987 3738.932735 gdpPercap_1992 2497.437901 gdpPercap_1997 3193.054604 gdpPercap_2002 4604.211737 gdpPercap_2007 5937.029526 Name: Albania, dtype: float64
print(data.ix[:, "gdpPercap_1952"])
country Albania 1601.056136 Austria 6137.076492 Belgium 8343.105127 Bosnia and Herzegovina 973.533195 Bulgaria 2444.286648 Croatia 3119.236520 Czech Republic 6876.140250 Denmark 9692.385245 Finland 6424.519071 France 7029.809327 Germany 7144.114393 Greece 3530.690067 Hungary 5263.673816 Iceland 7267.688428 Ireland 5210.280328 Italy 4931.404155 Montenegro 2647.585601 Netherlands 8941.571858 Norway 10095.421720 Poland 4029.329699 Portugal 3068.319867 Romania 3144.613186 Serbia 3581.459448 Slovak Republic 5074.659104 Slovenia 4215.041741 Spain 3834.034742 Sweden 8527.844662 Switzerland 14734.232750 Turkey 1969.100980 United Kingdom 9979.508487 Name: gdpPercap_1952, dtype: float64
print(data.ix['Italy':'Poland', 'gdpPercap_1962':'gdpPercap_1972'])
gdpPercap_1962 gdpPercap_1967 gdpPercap_1972 country Italy 8243.582340 10022.401310 12269.273780 Montenegro 4649.593785 5907.850937 7778.414017 Netherlands 12790.849560 15363.251360 18794.745670 Norway 13450.401510 16361.876470 18965.055510 Poland 5338.752143 6557.152776 8006.506993
print(data.ix['Italy':'Poland', 'gdpPercap_1962':'gdpPercap_1972'].min())
gdpPercap_1962 4649.593785 gdpPercap_1967 5907.850937 gdpPercap_1972 7778.414017 dtype: float64
me = data.ix['Italy':'Poland', 'gdpPercap_1962':'gdpPercap_1972']
subset = data.ix['Italy':'Poland', 'gdpPercap_1962':'gdpPercap_1972']
print('subset is:', subset)
subset is: gdpPercap_1962 gdpPercap_1967 gdpPercap_1972 country Italy 8243.582340 10022.401310 12269.273780 Montenegro 4649.593785 5907.850937 7778.414017 Netherlands 12790.849560 15363.251360 18794.745670 Norway 13450.401510 16361.876470 18965.055510 Poland 5338.752143 6557.152776 8006.506993
print('where are values large?\n', subset > 10000)
where are values large?
gdpPercap_1962 gdpPercap_1967 gdpPercap_1972
country
Italy False True True
Montenegro False False False
Netherlands True True True
Norway True True True
Poland False False False
mask = subset > 10000
print(subset[mask])
gdpPercap_1962 gdpPercap_1967 gdpPercap_1972 country Italy NaN 10022.40131 12269.27378 Montenegro NaN NaN NaN Netherlands 12790.84956 15363.25136 18794.74567 Norway 13450.40151 16361.87647 18965.05551 Poland NaN NaN NaN
print(subset[subset > 10000].describe())
gdpPercap_1962 gdpPercap_1967 gdpPercap_1972 count 2.000000 3.000000 3.000000 mean 13120.625535 13915.843047 16676.358320 std 466.373656 3408.589070 3817.597015 min 12790.849560 10022.401310 12269.273780 25% 12955.737547 12692.826335 15532.009725 50% 13120.625535 15363.251360 18794.745670 75% 13285.513523 15862.563915 18879.900590 max 13450.401510 16361.876470 18965.055510
%matplotlib inline
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.xlabel('Numbers')
plt.ylabel('Doubles')
<matplotlib.text.Text at 0x10ac0ee10>
data = pandas.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
data.ix['Australia'].plot()
plt.xticks(rotation=50)
(array([ 0., 2., 4., 6., 8., 10., 12.]), <a list of 7 Text xticklabel objects>)
data.T.plot()
plt.ylabel('GDP per capita')
plt.xticks(rotation=90)
(array([ 0., 2., 4., 6., 8., 10., 12.]), <a list of 7 Text xticklabel objects>)