• Skip to main content
  • Skip to primary sidebar

学習記録

プログラミング

データフレームの値をカンマ区切りにする

2018年11月28日 by 河副 太智 Leave a Comment

1
2
3
4
#金額をカンマ区切りにする
for i in range(len(df3['Trade Value (US$)'])):
    a = df3['Trade Value (US$)'][i]
    df3['Trade Value (US$)'][i] = "{:,}".format(float(a))

 

Filed Under: Pandas

リストにforで追加していく

2018年11月28日 by 河副 太智 Leave a Comment

1
2
3
4
#国名リスト化
partner = []
for var in df_s["Reporter"]:
    partner.append(var)

 

Filed Under: python3

APIが混雑している際に再取得する

2018年11月28日 by 河副 太智 Leave a Comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def fetch_url(url):
    for x in range(30):
        try:
            f = urllib.request.urlopen(url)
        except Exception as e:
            pass
            print("トライ30回中" + str(x + 1) + "回目")
            print("1分間の停止後リトライします。")
            sleep(60)
        else:
            return f
            break
    else:
        print("全て失敗しました")

 

Filed Under: python3

jsonファイルから指定の値を探す

2018年11月28日 by 河副 太智 Leave a Comment

以下のようなjsonファイルがあった場合

 

以下のようにjsonファイルを読み込む

1
2
3
#hsコードから品名を取得する
f = open('hscodeH4.json', 'r')
jsonData = json.load(f)

jsonData[‘results’][0][“id”]
を呼び出すと’ALL’が表示される

これはjsonファイルの’results’から見て0番目の辞書の中の”id”の
文字列を出力するからであり、

jsonData[‘results’][1][“id”]
を呼び出すと同じ原理で’TOTAL’が表示される

同じ要領で
jsonData[‘results’][0][“text”]
を呼び出すと’results’から見て0番目の辞書の中の”text”の
文字列を出力するので’All HS2012 categories’が表示される

 

jsonファイルの中のどこかの”text”が欲しい場合は
その”text”が存在する位置を探す作業が必要になる。

例えばid が”121299″の辞書にある”text”が欲しい場合、
以下のようにforを使用してデータを一つづつ見て行く。

そして[‘results’][i][“id”]と予め知っていたidが一致した時の
forで設定されているiの値が欲しい”text”を含む位置になるので
jsonData[‘results’][i][“text”]とすれば目的の”text”が手に入る

例

1
2
3
for i in range(len(jsonData["results"])):
    if jsonData['results'][i]["id"] == 121299:        
        itemname = jsonData['results'][i]["text"]

 

Filed Under: python3

List-Category-Postsでサムネイル表示

2018年11月28日 by 河副 太智 Leave a Comment

本文でのショートコードは以下になります

[catlist id=1 thumbnail=yes thumbnail_class=lcp_thumbnail]

そしてスタイルシートには以下のように記述します。

1
2
3
4
5
6
7
.lcp_thumbnail{
float: left;
}
 
.lcp_catlist li{
clear: both;
}

右に表示したければrightとすればok

Filed Under: css

WordPressのbodyclassを全体に有効化(Genesis)

2018年11月17日 by 河副 太智 Leave a Comment

Genesis公式サイトを参照

1
2
3
4
5
6
7
8
9
10
<?php
//* 上記コードは含まない
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
$classes[] = 'custom-class';
return $classes;
}

 

そのほかカテゴリ別に有効化するコードもある

Filed Under: Wordpress

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 4
  • Page 5
  • Page 6
  • Page 7
  • Page 8
  • Interim pages omitted …
  • Page 55
  • Go to Next Page »

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in