import time
import math
from itertools import combinations
!touch somefile
a = 1
b = 1.1
c = 'abc'
d = True
e = True and False
f = open('somefile')
g = c+c
h = c*3
a+=1
a,b,c,d,e,f,g,h
for i in range(10):
print(i)
if True:
print('this code runs')
else:
print('This not')
def power_3(x):
return x**3
print(power_3(10))
somelist = [5,5,9,2,3,5]
someotherlist = ['d','g',5,True,False, [5,3]]
sometuple = (5,6,7)
someothertuple = ('a','b',6)
somedict = {'a':5,
'b':9,
9:'g'
}
somedict
print(id(somelist))
somelist.append(5)
print(id(somelist))
[1,2,3] + [4,5,6]
[x**2 for x in [7,6,5,3]]
a = [4,5,6]
a.append(7)
a
a = [x**2 for x in range(0,21,2)]
a
a[2]
a[3:6]
a[::2]
a,b,c = sometuple
print(sometuple)
print(a)
print(b)
print(c)
import numpy
numpy.__version__
import numpy as np
np.array([1, 4, 2, 5, 3])
np.array([3.14, 4, 2, 3])
np.zeros(10, dtype=int)
np.ones((3, 5), dtype=float)
np.linspace(0, 10, 101)
np.random.random((5, 5))
np.arange(10)
a = np.linspace(0, 10, 101)
a.shape
a[5]
a[3:10]
a[-10:-1]
arr = np.arange(16)
arr
grid = arr.reshape((4, 4))
grid
upper, lower = np.vsplit(grid, [2])
print(upper)
print(lower)
left, right = np.hsplit(grid, [2])
print(left)
print(right)
np.min(grid)
np.max(grid)
np.sqrt(grid)
np.power(grid, 2)
import pandas as pd
s = pd.Series([1,3,5,np.nan,6,8])
s
dates = pd.date_range('20130101',periods=6)
dates
df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
df
df.A
df['A']
df.loc['2013-01-01']
df.applymap(lambda x: x+1)
df.applymap(lambda x: x>0)
df>0
%matplotlib inline
df.plot(figsize=(15,15))
df.groupby(pd.Grouper(freq='2d')).mean()
df.groupby(pd.Grouper(freq='3d')).mean()
df_1 = pd.concat([df,df], axis=1)
df_1
df_1.columns = ['A','B','C','D','E','F','G','H']
df_1.A+df_1.B
df_1.A + df_1.B - df_1.C - df_1.D
df_1.loc['2013-01-04', 'D']
df_1.loc['2013-01-04', 'D'] = 100
df_1
df_1.describe()
df_1.shape
df_1.info(memory_usage='deep')