Python 27 2月 2019 データをopenするときの第2引数 r+, w+, a+の違いって何?[Python] 導入 "r+" と "w+" と "a+" における挙動の違い "r+" の場合 "w+" の場合 "a+" の場合 発展的な内容 Openした際のポインタ位置の違い f.read() した際の違い […] 続きを読む
Python 12 2月 2019 Pythonでテキストファイルを1行ずつ読み込む[Python] with open("text.txt") as f: for line in f: print(line) withを使いたくなければ, f = open("text.txt") for line […] 続きを読む
Pandas 25 1月 2019 pd.read_csvでUnicodeDecodeErrorがでるときの対処法[Python][Pandas] Windowsでpd.read_csvを使うと頻繁にエラーがでる. エラーがでにくいcsvの読み込み方を見つけたので,メモ. df = pd.read_csv("./hoge.csv", engine[…] 続きを読む
Python 9 1月 2019 置換する文字を複数指定[Python] import re patterns = "dog|cat|fox" repl = "animal" sentence = "dog, cat, fox, pen." re.sub(patterns,[…] 続きを読む
Python 4 1月 2019 f'{hoge}’はフォーマット文字列リテラル(f-strings)[Python] Kaggleを眺めていると見慣れない記法を発見。 x = str(x) for punct in puncts: x = x.replace(punct, f' {punct} ') return x[…] 続きを読む
MeCab 3 1月 2019 MeCabで日本語の分かち書き[MeCab][Python] import MeCab mecab = MeCab.Tagger ("-Owakati") print(mecab.parse("平成最後の初売りセールが開催中")) 平成 最後 の 初 売り セー[…] 続きを読む
Python 23 12月 2018 Pythonでhtmlのファイルを読み込む方法[Python][Beautifulsoup] from bs4 import BeautifulSoup import re links = [] html_path = "./hoge.html" with open(html_path) as[…] 続きを読む
Python 23 12月 2018 Pythonでテキストファイルから1行づつ読み込んで処理を行う[Python] fname = "url.txt" with open(fname) as f: for line in f: contents = requests.get(line) time.sleep(1.5[…] 続きを読む
Numpy 23 12月 2018 Pythonで範囲を指定して乱数を生成[Python][Numpy] time.sleep(*) の変数をランダムに変えたかったときに使った方法を記す。 import numpy as np np.random.randint(10, 20) >> 14 ち[…] 続きを読む
Gensim 6 11月 2018 gensimで英語の分かち書き[gensim][Python] from gensim.utils import tokenize list(tokenize("i am happy")) >>[…] 続きを読む