This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
pd.concat([df1, df2], axis=0, ignore_index=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime as dt | |
def get_timestamp(): | |
dt_obj = dt.now() | |
return dt_obj.strftime("%Y/%m/%d, %H:%M:%S") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
current_dir = os.path.dirname(os.path.abspath("__file__")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
環境変数の設定の仕方 | |
- ~/.config/fish/config.fishに書き込む |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __str__(self) | |
# printやformat文の引数としてオブジェクトが指定された時に | |
# 呼び出され、非公式の文字列表現を返す。 | |
def __call__() | |
# classを直接呼び出す時に実行される。 | |
def __repr__() | |
# 正式なオブジェクトの内容を文字列で返し、 | |
# インタプリターが同値性をチェックする時に使われる。 |