Skip to content

Instantly share code, notes, and snippets.

select count(case when status='200 OK') as ok,count(case when status!='200 OK') as error from date_status group by time;
@okdolly-001
okdolly-001 / load_img.py
Created June 25, 2018 01:44
load image from a directory #matplotlib #image #cv
import matplotlib.image as mpimg
import glob
import os
def load_data(dir_name = 'plates'):
""" Your implementation """
data_path = os.path.join(dir_name, '*g')
files = glob.glob(data_path)
data = [mpimg.imread(img) for img in files]
return data
@okdolly-001
okdolly-001 / groupby.py
Created June 9, 2018 10:40
Groupby #pandas
import pandas as pd
df = pd.DataFrame(
{
'AAA': [1,1,1,2,2,2,2,3,3],
'BBB': [2,1,3,4,5,1,2,3,7]
}
)
print(df,'\n')
@okdolly-001
okdolly-001 / check_path.py
Created May 16, 2018 06:32
Check python module os path
import os.path
import my_module
print(os.path.abspath(my_module.__file__))
@okdolly-001
okdolly-001 / One-hot-encoding-np.py
Created April 23, 2018 04:10
One-hot encoding #numpy
def get_one_hot(targets, nb_classes):
return np.eye(nb_classes)[np.array(targets).reshape(-1)]
This is what happens:
np.eye(3)
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
@okdolly-001
okdolly-001 / subplot_img.py
Created April 21, 2018 01:59
Display image and title #jupyter #matplotlib
Set a subplots. Display image and title inside a for-loop.
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
fig, axs = plt.subplots(2,5, figsize=(15, 6), facecolor='w', edgecolor='k')
fig.subplots_adjust(hspace = .5, wspace=.001)
axs = axs.ravel()
@okdolly-001
okdolly-001 / jupyter_img.html
Created April 14, 2018 23:08
markdown insert img (jupyter)
<img src="images/1.png" alt="Drawing" style="width: 800px;"/>
@okdolly-001
okdolly-001 / basic_tensorflow.py
Last active April 3, 2018 03:03
TensorFlow beginner #tensorflow
correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(labels, 1))
#tf.argmax finds the index of the largest value along axis = 1.tf.equal checks whether the two are equal, if the output index (predicted classes are the same, then correct prediction is 1).
@okdolly-001
okdolly-001 / leetcode.py
Created April 1, 2018 02:48
Coding interview snippets
1.Remove duplicates in a list
cleanlist = []
for n in oldlist:
if n not in cleanlist:
cleanlist.append(n)
@okdolly-001
okdolly-001 / replace_pandas.py
Created March 22, 2018 01:39
Replace values in dataframe from another dataframe ? #pandas
1. Substitute the NaN's in a dataframe with values from another dataframe
If you have two DataFrames of the same shape, then:
df[df.isnull()] = d2
2.Replace values in a dataframe with values from another dataframe by conditions