Forwarded from Khafizullo
when using groupby do not forget to use as_index
df['date'] = pd.to_datetime(df.date, dayfirst=True)
# df['month'] = df['date'].dt.month
# df['month_year'] = df['full_datetime'].dt.strftime('%m-%Y')
# df['date'] = df['date'].dt.to_period('M')
when working with dates
# df['month'] = df['date'].dt.month
# df['month_year'] = df['full_datetime'].dt.strftime('%m-%Y')
# df['date'] = df['date'].dt.to_period('M')
when working with dates
x = np.array([-1,0,1.4],dtype='bool')
y = np.array([-1,0,1.4],dtype='int16')
z = np.array([-1,0,1.4],dtype='float64')
it says boolean works faster
y = np.array([-1,0,1.4],dtype='int16')
z = np.array([-1,0,1.4],dtype='float64')
it says boolean works faster
x = np.array([0,0,0],dtype='uint8')
x[0] = 255
x[1] = x[0] + 1
x[2] = x[1] + 1
print(x)
it means uint8 contains only 255 character
x[0] = 255
x[1] = x[0] + 1
x[2] = x[1] + 1
print(x)
it means uint8 contains only 255 character
x = np.array([-1,0,1,10],dtype='float64')
print( x / 0 )
y = 10 / 0 # core Python
-inf nan inf inf it says when dividing 0 to 0
print( x / 0 )
y = 10 / 0 # core Python
-inf nan inf inf it says when dividing 0 to 0
a = (np.inf == np.inf)
b = (np.nan == np.nan) # Can not compare nan to nan!
c = np.isnan(np.nan)
you can compare inf to inf
but you can not compare nan to nan
b = (np.nan == np.nan) # Can not compare nan to nan!
c = np.isnan(np.nan)
you can compare inf to inf
but you can not compare nan to nan
a = np.array([1,2,3,4,5],dtype='float64')
# a = np.arange(5,dtype='uint8') + 1
print([type(a_element) for a_element in a])
for using arrange used list comprehension with type and for
# a = np.arange(5,dtype='uint8') + 1
print([type(a_element) for a_element in a])
for using arrange used list comprehension with type and for
# Assigning elements of an array
z[1,0] = -1
z[2] = [4,5,7] # assign whole row from a list
z[:,0] = np.array([4.2,5.2,6.2,7.2,8.2]) # assign column from nparray
z[:2,1]=9.3
z[3][1]=-2 # note double bracket indexing
print(z)
z[1,0] = -1
z[2] = [4,5,7] # assign whole row from a list
z[:,0] = np.array([4.2,5.2,6.2,7.2,8.2]) # assign column from nparray
z[:2,1]=9.3
z[3][1]=-2 # note double bracket indexing
print(z)
print(b)
print(b*b) # element by element
print(c*c) # matrix multiplication
when multipying the ndarray you can do it one by one but with matrix you can not but exclusions there is when multipying you can use .transpose() to multiply one by one in matrix
print(b*b) # element by element
print(c*c) # matrix multiplication
when multipying the ndarray you can do it one by one but with matrix you can not but exclusions there is when multipying you can use .transpose() to multiply one by one in matrix
a = np.empty(25,'float64') # not initialized !
b = np.zeros(5) # initialized with zeros
c = np.ones(5)
d = np.arange(10)
e = np.linspace(2, 3, 100) # fill between 2 and 3 with 10 points
print(a,b,c,d,e,sep='\n\n')
empty random 25 numbers with float 64 type
np.zeros(10) with filling out the 10 zeros
np.ones(5) makes filling with 5 ones
arrange you can do (from x, to y)
linspace(from x, to y, with 100 parts)
b = np.zeros(5) # initialized with zeros
c = np.ones(5)
d = np.arange(10)
e = np.linspace(2, 3, 100) # fill between 2 and 3 with 10 points
print(a,b,c,d,e,sep='\n\n')
empty random 25 numbers with float 64 type
np.zeros(10) with filling out the 10 zeros
np.ones(5) makes filling with 5 ones
arrange you can do (from x, to y)
linspace(from x, to y, with 100 parts)
z = np.linspace(0, 2, 15)
z = np.reshape(z,[5,3])
with linespace and reshaping
z = np.reshape(z,[5,3])
with linespace and reshaping
z = np.linspace(0, 2, 12)
z = np.reshape(z,[4,3])
print(z,end='\n\n')
with reshape and use end = \n\n
z = np.reshape(z,[4,3])
print(z,end='\n\n')
with reshape and use end = \n\n
mask = np.logical_and(z>1.0,z<1.75)
logical_and is equal to AND
logical_and is equal to AND
x = np.arange(3) + 5
y = np.ones((3,3))
print(x,y,x+y,sep='\n\n')
y = np.ones((3,3))
print(x,y,x+y,sep='\n\n')
plt.bar(x_indexes - width, dev_y, width = width, color = 'k', label = 'All Devs')
bor bar plot using first x and y then proper width then color then label we have linestyle and linewidth alpha
bor bar plot using first x and y then proper width then color then label we have linestyle and linewidth alpha