pythonの基礎構文についてのメモ
pip
update
pip install -U pymongo
バージョン指定
pip install pymongo==2.6.2
その他
env
環境の作成
python -m venv <name>
active
source <name>/bin/activate
deactivate
deactivate
requirements
pip freeze > requirements.txt
oandapy関連
取得したデータの時間の成形
デフォルトの形式だと後部じゃ邪魔なので整形する
from datetime import datetime label_x = df["time"].apply(lambda x: datetime.strptime(x,"%Y-%m-%dT%H:%M:%S.%fZ") new_format = "%Y-%m-%dT%H:%M" label_x = label_x.apply(lambda x: x.strftime(new_format))
json
データの書き込み
>>> import json >>> with open("test.json","w") as f: ... a = {"t":"test"} ... json.dump(a,f)
データの読み込み
>>> data = open("test.json") >>> json.load(data) {'t': 'test'}
文字列関連
replace():文字の入れ替えと削除
>>> my_str = "テスト" >>> my_str.replace("テ","コ") 'コスト' >>> my_str 'テスト' >>> my_str.replace("テ","") 'スト'