プログラミング

シンプルに使い方を紹介

【Wordpress】1ページサイトを作成する

利用準備

  1. 以下のページで会員登録する
    ネットオウル /新規会員登録
    ・ メールアドレスを入力
    ・ 確認メールに記載のある認証IDを確認
    ・ 認証IDを入力し「登録フォームへ移動」をクリック
    f:id:eerf0309458:20170711182404p:plain
  2. 以下のページから管理画面にログインする
    ネットオウル /ユーザーログイン
  3. 提供サービスの中からWpblogの「新規申込」をクリック
    f:id:eerf0309458:20170711182745p:plain
  4. 新規インストー
    ・必要情報を入力
    ・「次へ進む」をクリック
    ・登録情報を確認し、「確定」をクリック
    f:id:eerf0309458:20170711182835p:plain f:id:eerf0309458:20170711183039p:plain
  5. 設定が終了するまで15分後程度待ちます

テーマの変更

  1. Wordpress管理画面へ
    Wordpress一覧をクリック
  2. テーマの変更
    ・管理画面の外観 -> テーマ -> 新規追加 ・「Sequential」を検索 ・インストール、有効化

f:id:eerf0309458:20170711200750p:plain

plyrパッケージ

概要

  • ある指定した特徴量に応じてデータを分割(Split)
  • 分割したデータに対する関数の適用(Apply)
  • 分割したデータを再結合して(list, data.frame, arrayでの)結果の出力(Combine)
    という操作を一つの関数で実行することができる。

使い方

ddply

  • 月毎の行数
ddply(tokyo.2014,.(month),nrow)
   month V1
1     01 31
2     02 28
3     03 31
4     04 30
.      .  .
.      .  .
  • 月毎のA,B,C,D,E合計
ddply(tokyo.2014,.(month),colwise(sum,.(A,B,C,D,E)))
   month      A        B     C        D        E
1     01  22071  43799.0 15360  34747.0  11658.0
2     02  19727  45060.5 24549  35141.5  11569.5
3     03  35237  50806.0 24449  51871.0  28715.0
4     04  55324  88766.0 37782  85998.0  55821.0
.      .      .        .     .        .        .
.      .      .        .     .        .        .
  • 月、曜日毎のA,B,C,D,E平均値
ddply(tokyo.2014,.(month,week),colwise(mean,.(A,B,C,D,E)))
   month week        A        B        C        D        E
1     01    1 1027.800 1508.400  515.400 1065.600  369.800
2     01    2  583.200 1287.200  444.600 1102.400  376.200
3     01    3  673.600 1485.600  564.600 1365.400  394.000
.      .    .        .        .        .        .        .
.      .    .        .        .        .        .        .
82    12    5  689.000 2120.000  453.000 1215.000  653.500
83    12    6  760.200 1787.600  495.600 1225.400  636.600
84    12    7  557.600 1706.800  583.200 1143.600  555.000
  • 月毎に数値列の平均値を取得する
ddply(tokyo.2014,.(month),colwise(mean,is.numeric))
  • numericな列のみを取得する
data[sapply(data,is.numeric)]

参考資料

plyrパッケージの使い方メモ

【Android】今日の日付を取得する

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public static String getNowDate(){
    Date now = new Date(System.currentTimeMillis());
    DateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH時mm分");
    String nowText = formatter.format(now);
    return nowText;
}

【Python】SQLiteで構文中に変数を挿入する

テストプログラム

# -*- coding:utf-8 -*-

import sqlite3

conn = sqlite3.connect("test.db")

# テーブルの作成
conn.execute("create table tbl_name(id, name)")

# データの挿入
conn.execute("insert into tbl_name values( ?, ? )", [ 1, "Sato" ])

# データの複数挿入
conn.executemany("insert into tbl_name values( ?, ? )",
               [ ( 2, "Suzuki" ), ( 3, "Tanaka" ) ])

conn.commit()
conn.close()

解説

SQLite

SQLiteではデータ挿入は、以下の書式で行われます。

INSERT INTO テーブル名 VALUES(値1, 値2, ...);

例えば、「ID、名前、年齢、住所」のようなテーブルであれば、

create table user(id integer, name text,
                              age integer, address text);
insert into user values(1, 'Sato', 18, 'Tokyo');

上記のようにデータの挿入を行います。

Python

Pythonで上記と同様の事は、以下の記述で行えます。(中に名前のようにテキストを含むものをしていするときは、「"」と「'」のどちらかを入れ子にする必要があります.同様の文字を利用するとエラーになります.)

conn.execute("create table tbl_name(id integer,name text,
                                                age integer,address text)")
conn.execute("insert into tbl_name values(1,'Sato')")

上記の記述に加えPython上では、「?」による変数の置き換えが可能です。(「[」部には勿論変数を指定可能です)

conn.execute("create table tbl_name(id integer,name text,
                                              age integer,address text)")
conn.execute("insert into tbl_name values(?,?)",[1,"Sato"])

複数の変数を挿入する場合は、以下のような記述で可能です。

conn.execute("create table tbl_name(id integer,name text,
                                               age integer,address text)")
conn.executemany("insert into tbl_name values( ?, ? )",
                                     [ ( 2, "Suzuki" ), ( 3, "Tanaka" ) ])

list = [(1,'Sato'),(2,'Suzuki'),(3,'Tanaka')]
conn.executemany("insert into tbl_name values( ?, ? )", list)

結果の確認方法

SQLite

$ sqlite3 test.db
sqlite3 > select * from tbl_name;

Python

# -*- coding:utf-8 -*-

import sqlite3

conn = sqlite3.connect("test.db")
cur = conn.cursor()

cur.execute('select * from tbl_name')

for r in cur.fetchall():
    print r[0], r[1]
    
conn.commit()
conn.close()
cur.close()