git rm --cached 'file name'
ファイルを管理対象から外す(-rでディレクトリごと)
git stash
一時的に変更を保存する
git stash apply stash@{num}
一時的に保存した変更を元に戻す
git checkout
sorted(iterable, key) | |
# - iterable: list, dict | |
# - key: function called to each element before comparison | |
score = {'kokugo': 33, 'sansuu': 85, 'eigo': 60} | |
# when you want to sort by key | |
score_sorted = sorted(score.items(), key=lambda x:x[0]) | |
# when you want to sort by value | |
score_sorted = sorted(score.items(), key=lambda x:x[1], reverse=True) |
import matplotlib.pyplot as plt | |
plt.pie(fraction, startangle, wedgeprops, autopct, explode, **) | |
# example: plt.pie(frac, startangle=90, wedgeprops={'linewidth': 3, 'edgecolor':"white"}, autopct="%1.1f%%", explode=[0.2, 0, 0, 0, 0] | |
# fraction: total of fraction should be 1 | |
# startangle: startangle | |
# wedgeprops: edge props | |
# autopct: show percentage | |
# explode: array for explode |
s = {1,2,3} | |
s.add(4) | |
print(s) | |
# {1,2,3,4} | |
s.remove(3) | |
print(s) | |
# {1,2,4} | |
s1 = {1,2,3} |
# linecache module allows one to get any line fromm python source code file | |
import linecache | |
linecache.getline(filename, line_number, module_globals=None) | |
# get line line_number from file named filename | |
# ex. line = linecache.getline('./test.txt', 8) | |
# get 8th line from test.txt |
import pandas as pd | |
# save single sheet for excel file | |
df.to_excel(fp, index=True, columns=True) | |
# save multiple sheets for excel file | |
with pd.ExcelWriter(fp) as writer: | |
df1.to_excel(writer, sheet_name='sheet1') | |
df2.to_excel(writer, sheet_name='sheet2') |
import pandas as pd | |
pd.concat([df1, df2], axis=0, ignore_index=False) |
import torch | |
# save parameters | |
torch.save(model.state_dict(), PATH) | |
# load parameters | |
model = ModelClass(*args, **kwargs) | |
model.load_state_dict(torch.load(PATH)) | |
git rm --cached 'file name'
ファイルを管理対象から外す(-rでディレクトリごと)
git stash
一時的に変更を保存する
git stash apply stash@{num}
一時的に保存した変更を元に戻す
git checkout
pythonにおけるstacktraceは、例外発生時に、sys.las_traceback という変数にtracebackオブジェクトとして格納される。
その中身を参照するためにsys.exc_info()
が用意されている。
https://vaaaaaanquish.hatenablog.com/entry/2017/12/14/183225