Skip to content

Instantly share code, notes, and snippets.

View leemengtw's full-sized avatar
🤖
I write random stuffs about AI/ML/DS @ leemeng.tw (in Chinese)

Meng Lee leemengtw

🤖
I write random stuffs about AI/ML/DS @ leemeng.tw (in Chinese)
View GitHub Profile
heroku run pip freeze | grep tensorflow-tensorboard | xargs pip uninstall -y
@leemengtw
leemengtw / submit_file_after_select.html
Last active December 21, 2017 01:24
選完檔案後直接提交form 並隱藏submit button
<form method=post action="{{ url_for('make_prediction') }}" enctype=multipart/form-data>
<label class="btn btn-default btn-file">
Browse<input type="file" name=file style="display: none;" accept="image/*" onchange="this.form.submit();">
</label>
<button type="submit" style="display: none;"></button>
</form>
References
- https://stackoverflow.com/questions/4730666/post-immediately-after-select-a-file
import tensorflow as tf
above_threshold = (box_class_scores >= threshold) # shape: (19, 19, 5)
scores = tf.boolean_mask(box_class_scores, above_threshold)
@leemengtw
leemengtw / push_to_multi_repo_by_using_sourcetree.md
Last active December 21, 2017 01:23
使用souce tree一次push到兩個remote repo
@leemengtw
leemengtw / color_column_by_value_in_dataframe.py
Last active December 21, 2017 01:23
Dataframe把某個欄位依照不同的值設定不同背景顏色(基本上就是使用applymap, 然後自己定義一個callable 來依照不同值給不同顏色. 要選一個colume就使用subset param. 然後顏色的設定就是 CSS;applymap預設是針對所有cells, 所以如果要決定套用的範圍用subset)
def color_picker(x):
if x == '東京':
color_text = 'rgb(153, 204, 255)'
else:
color_text = 'rgb(153, 255, 51)'
return 'background-color: {}'.format(color_text)
df.style.applymap(color_picker, subset=pd.IndexSlice[:, ['col c']]
import seaborn as sns
cm = sns.light_palette("green", as_cmap=True)
df2.style.background_gradient(cmap=cm, subset=pd.IndexSlice[:, ['col1', 'col2']])
@leemengtw
leemengtw / add_new_column_to_dataframe.py
Last active December 21, 2017 01:22
在dataframe追加新的column
df1['e'] = Series(np.random.randn(sLength), index=df1.index)
References
- https://stackoverflow.com/questions/12555323/adding-new-column-to-existing-dataframe-in-python-pandas
import pandas as pd
df = pd.DataFrame()
df.to_csv('YOUR_CSV_NAME', encoding='cp932')
import json
import requests
ES_URL = "your es cluster url including index and _type like .../index1/doc_type"
query = {
"size": 150,
"query": {
"bool": {
"must": [
{
def get_phone_stat(group):
return pd.DataFrame({
'new_column': group['duration'].sum()
}, index=[group.name])
df1 = df_phone.groupby('action').apply(get_phone_stat)
df1.index = df1.index.droplevel(0)