• Skip to main content
  • Skip to primary sidebar

学習記録

河副 太智

文字列の改行(変数内)

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

ジュピターではスラッシュが¥で表示される
¥の直後にスペースがあるとエラーになる

1
2
3
4
5
6
7
8
9
10
11
exprice = "<h1 id=\"rittai\">Export Trade Statistics of \""+ itemname + "\"(HScode:" + com +")" + "</h1><br><br>" + class_tip + \
    "The graph below shows export statistics of<br><b>" + itemname + "</b>(HScode:" + com + ") worldwide in " + str(df3["Year"][0]) + class_end + \
    tag_st + up_url + com +"expvalue"+ ".html\"" + end_value+class_tip+ \
    "The statistic shows a ranking of the top export countries worldwide in " + str(df3["Year"][0])+ "<br>" +\
    partner[0] + " ranked first in exports of \"" + itemname +"\"" + " Total export value " +  "{:,}".format(valuee[0]) + "USD <br>"  + \
    partner[0] + " is followed by " + \
    partner[1] + ": " +  "{:,}".format(valuee[1]) + "USD <br>" +\
    partner[2] + ": " +  "{:,}".format(valuee[2]) + "USD <br>" +\
    partner[3] + ": " +  "{:,}".format(valuee[3]) + "USD <br>" +\
    partner[4] + ": " +  "{:,}".format(valuee[4]) + "USD and <br>" +\
    partner[5] + ": " +  "{:,}".format(valuee[5]) + "USD <br>" + "<p>"+class_end

 

Filed Under: python3

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

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

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 9
  • Page 10
  • Page 11
  • Page 12
  • Page 13
  • Interim pages omitted …
  • Page 66
  • 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