Python

Thumbnail of post image 173

with open("text.txt") as f:for line in f:print(line)

withを使いたくなければ,

f = open("text.txt")for line in f:print(line)f. ...

Pandas,Python

Thumbnail of post image 189

Windowsでpd.read_csvを使うと頻繁にエラーがでる.

エラーがでにくいcsvの読み込み方を見つけたので,メモ.

df = pd.read_csv("./hoge.csv", engine="python ...

Python

Thumbnail of post image 197

import repatterns = "dog|cat|fox"repl = "animal"sentence = "dog, cat, fox, pen."re.sub(patterns, repl, sentence)>> ...

Python

Thumbnail of post image 193

Kaggleを眺めていると見慣れない記法を発見。

x = str(x)for punct in puncts:x = x.replace(punct, f' {punct} ')return x

ん? f’ {p ...

MeCab,Python

Thumbnail of post image 004

import MeCabmecab = MeCab.Tagger ("-Owakati")print(mecab.parse("平成最後の初売りセールが開催中"))平成 最後 の 初 売り セール が 開催 中

OR

import ...

Python

Thumbnail of post image 007

from bs4 import BeautifulSoupimport relinks = []html_path = "./hoge.html"with open(html_path) as f:html = f.read()soup = ...

Python

Thumbnail of post image 056

fname = "url.txt"with open(fname) as f:for line in f:contents = requests.get(line)time.sleep(1.5)

Numpy,Python

Thumbnail of post image 064

time.sleep(*) の変数をランダムに変えたかったときに使った方法を記す。

import numpy as npnp.random.randint(10, 20)>> 14

ちなみに記法としては以下のよう ...

Gensim,Python

Thumbnail of post image 072

from gensim.utils import tokenizelist(tokenize("i am happy"))>>

Pandas,Python

Thumbnail of post image 165

hogeというフォルダの中に複数のCSVが配置されているとき、

以下のコードで複数のCSVを一つのDataFrame(表)としてまとめることが可能

from glob import globimport pandas ...