Skip to content

Instantly share code, notes, and snippets.

View yatakeke's full-sized avatar

Yatakeke a.k.a Agile Zamurai yatakeke

View GitHub Profile
import pandas as pd
pd.concat([df1, df2], axis=0, ignore_index=False)
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')
# 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
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}
@yatakeke
yatakeke / matplotlib_make_pie_chart.py
Last active August 1, 2020 07:32
matplotlib pie chart
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
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)
from datetime import datetime as dt
def get_timestamp():
dt_obj = dt.now()
return dt_obj.strftime("%Y/%m/%d, %H:%M:%S")
import os
current_dir = os.path.dirname(os.path.abspath("__file__"))
@yatakeke
yatakeke / fish
Created February 16, 2019 01:49
fishについての知見
環境変数の設定の仕方
- ~/.config/fish/config.fishに書き込む
@yatakeke
yatakeke / magic_methods.py
Last active February 18, 2019 01:51
Pythonの特殊メソッドについて
def __str__(self)
# printやformat文の引数としてオブジェクトが指定された時に
# 呼び出され、非公式の文字列表現を返す。
def __call__()
# classを直接呼び出す時に実行される。
def __repr__()
# 正式なオブジェクトの内容を文字列で返し、
# インタプリターが同値性をチェックする時に使われる。