2018-01-01から1年間の記事一覧

関西電力の電気データをDataFrameにしてみた。

pandasからのplotって手軽で良い。 関西電力は、消費電力をCSVでダウンロードできる。 pandas学習がてらにread_csvをしてみました。 温度が高いと電気代上がるのではなく、冬のエコキュートの電気代が高いので温度に対して負の相関になった。

json.dump()

import json from io import StringIO io = StringIO() json.dump(['streaming API'], io)#dump()は書き出す io.getvalue() '["streaming API"]'

rjust(),ljust(),zfill()たち

In [49]: s = 'Hello, world' ...: print (str(s)) ...: print (repr(s))#インタープリタが読めるよう表現を生成する。 ...: print(s.rjust(30))#30文字の中で右寄せる。 ...: print(s.ljust(30))#30文字の中で左寄せる。 ...: print(s.zfill(30))#30文字の…

np.whereって

import numpy as np i = np.min(np.where(y > 0.5)) とはどういう意味か。 whereって In [1]: import numpy as np In [2]: a = np.arange(8).reshape((2, 4)) In [3]: np.where(a > 2) Out[3]: (array([0, 1, 1, 1, 1], dtype=int64), array([3, 0, 1, 2, 3]…

np.fmodに絡んだnumpy記載メモ

x_train = x[np.fmod(range(16), 4) !=i] という記述があり、意味がわからず、調べて理解したのでメモ i には、 for i in range(0,4) x は、np.array x = np.array([15.42555012, 23.00811234, 5.00285937, 12.55831432, 8.66889727, 7.30846487, 9.65650528…

f表記がPython3.6から使える

item1 = 'apple' item2 = 'bananas' item3 = 'grapes' print('At the grocery store, I bought some {0} and {1} and {2}.'.format(item1,item2,item3)) print('At the grocery store, I bought some {0} and {1} and {2}.'.format('apple',2,3))#intも入れ…

shelve したあと、中身みたいとき。

# 変数専用ファイルにデータを保管 pickle モジュールを使う import shelve shelve_file = shelve.open('friend') my_friend = ['A_san', 'B_san', 'C_san'] shelve_file['my_friend'] = my_friend print(shelve_file.keys) a =list(map(str,shelve_file)) p…

jupyter_notebookでのモジュールを自動で読み込み直すやつ

%reload_ext autoreload %autoreload 2

mapがわからなくなるのでメモ

a = list(range(1,100)) print(list(map(str, a)))

たまにsplitとjoinがわからなくなるのでメモ(ついでにmap)

a = '1 2 3 4 5 6 7 8' b = list(a.split()) print(b) ['1', '2', '3', '4', '5', '6', '7', '8'] c= ",".join(b) print(type(c)) <class 'str'> d = list(map(int,b)) print(d) [1, 2, 3, 4, 5, 6, 7, 8]</class>

pwdとcdをpython os モジュールで やってみる。

import os #カレントディレクトリ os.getcwd() #ディレクトリ移動(一つ上のディレクトリへ) os.chdir('../')

train_test_splitでtrain_sizeを指定しないとどんな割合でテストデータ作るのか?

train_sizeを指定しないと、75%25%みたい。 from sklearn.model_selection import train_test_split as split # 学習用データ,テスト用データ,学習用の正解ラベル, テスト用の正解ラベル = train_test_split(データ, データ正解ラベル,train_size=学習用デー…

train_test_split の書き方

from sklearn.model_selection import train_test_split as split x_train, x_test, y_train, y_test = split(iris.data,iris.target, train_size=0.85, test_size=0.15) 学習用データ,テスト用データ,学習用の正解ラベル, テスト用の正解ラベル = train_tes…

KitematicからのOffical MySQLのパスワードを設定

Kitematicから「General」から「Envorionment Variables」に KEYにMYSQL_ROOT_PASSWORD VALUEに設定したパスワードを入れる。