• Skip to main content
  • Skip to primary sidebar

学習記録

CSVの読み込み

2017年11月29日 by 河副 太智 Leave a Comment

 

1
2
3
4
5
6
7
# データセット読込
from pandas import read_csv
dataframe = read_csv('aaa.csv',
usecols=[1],engine='python',  skipfooter=3)
 
dataset = dataframe.values
dataset = dataset.astype('float32')

usecols=[1]は読み込むcsvの列を指定[1]であれば2列目を縦に読み込む
engine=’python’ か’c’のどちらか
skipfooter=3はデータ末尾の3行はフッターとみなし読み込まない

1
2
#カラム(一行目にそれぞれの数値が何を表しているか)
dataset.columns=["sepal length", "sepal width", "petal length", "petal width", "class"]

 

わかりやすい一覧↓
Pandasのread_csvの全引数を解説

Filed Under: Pandas

Jupyterの文、単語を検索

2017年11月29日 by 河副 太智 Leave a Comment

find ./ -type f -print | xargs grep ‘キーワード’

Filed Under: Python 基本

辞書の文字数カウント collectionsモジュールのdefaultdict(型)

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

jisho = defaultdict(intかlist等の型)

 

 #これで変数jishoが辞書になる

例

from collections import defaultdict

jisho = defaultdict(int)
lst = [“a”, “b”, “c”, “b”, “a”, “e”]

for key in lst:
jisho[key] += 1

print (jisho)

 例:2
1
<span role="presentation"><span class="cm-keyword">from</span> <span class="cm-variable">collections</span> <span class="cm-keyword">import</span> <span class="cm-variable">defaultdict</span> </span>

1
<span role="presentation"><span class="cm-comment"># 文字列description</span></span>

1
<span role="presentation"><span class="cm-variable">description</span> = <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"AFL intends to import  PVC-insulated  and  XLPE-insulated  bunched copper wire from Honduras.  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"The insulated wire will be used in the U.S. in the production of automotive wire harnesses. "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"Copper strands, classifiable under subheading 7413.00, Harmonized Tariff System of the United States  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"(HTSUS); polyvinyl chloride (PVC) pellets, classifiable under subheading 3904.21, HTSUS; and "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"cross-link polyethylene (XLPE) pellets, classifiable under subheading 3901.30, HTSUS, all of U.S. origin will be exported to Honduras.  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"The copper strands will be annealed in the U.S. and will be wound onto reels,  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"containing between six and 14 untwisted and non-bunched copper strands. In Honduras,  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"the strands are fed into a buncher, which arranges the strands in specific geometric orientations,  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"with specific twist lengths ( lay lengths ) based on the specifications of the end use application "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"( lay plate ). The strands then enter the  compaction die  which sets the diameter and length of  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"the specific products, resulting in the creation of  bunched wire.  By using strands of various "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"sizes and numbers of strands, different sizes of bunched wire are produced. It is "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"stated that the size of the bunched wire determines its electrical current carrying capacity  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"and physical strength. The bunched wire will contain between seven and 104 strands, with American "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"Wire Gauge (AWG) measurements varying between 10 and 22. It is stated that the AWG level identifies the  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"diameter, electrical current capacity and temperature  rating,  or maximum temperature levels within  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"which the wire can function. From the compaction die, the bunched wire enters the  bow , which rotates "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"and twists the bunched wire, based on the needs of the given end use of the wire. "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"Next, the bunched wire is wound onto a reel and prepared for insulation with either PVC or XLPE.  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"The compound is melted and pumped through the extruder line. In the extruder line, a  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"rotating wheel pulls the copper wire, and the compound is extruded over the wire.  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"If PVC is used, the material is cooled following a controlled cooling with water,  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"which solidifies the compound around the bunched wire. It is stated that PVC-insulated  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"wire has a lower temperature rating and is more likely to be used in applications  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"where it is subject to less intense heat. If XLPE is used, a steam vulcanization process  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"is required which causes a chemical reaction in the extruded XLPE, causing  "</span> <span class="cm-operator">+</span> <span class="cm-error">\</span></span>

1
<span role="presentation"><span class="cm-string">"crosslinking  in the underlying polymer chain. It is stated that  crosslinking"</span></span>

1
<span role="presentation">​</span>

1
<span role="presentation"><span class="cm-comment"># defaultdictを定義</span></span>

1
<span role="presentation"><span class="cm-variable">moji</span> = <span class="cm-variable">defaultdict</span>(<span class="cm-builtin">int</span>)<span class="cm-comment">#これが辞書になる</span></span>

1
<span role="presentation">​</span>

1
<span role="presentation"><span class="cm-comment"># 文字の出現回数を記録</span></span>

1
<span role="presentation"><span class="cm-keyword">for</span> <span class="cm-variable">key</span> <span class="cm-keyword">in</span> <span class="cm-variable">description</span>:</span>

1
<span role="presentation">    <span class="cm-variable">moji</span>[<span class="cm-variable">key</span>] += <span class="cm-number">1</span></span>

1
<span role="presentation">​</span>

1
<span role="presentation"><span class="cm-comment"># ソートし、上位10要素を出力して下さい</span></span>

1
<span role="presentation"><span class="cm-builtin">print</span>(<span class="cm-builtin">sorted</span>(<span class="cm-variable">moji</span>.<span class="cm-property">items</span>(), <span class="cm-variable">key</span>=<span class="cm-keyword">lambda</span> <span class="cm-variable">x</span>: <span class="cm-variable">x</span>[<span class="cm-number">1</span>], <span class="cm-variable">reverse</span>=<span class="cm-keyword">True</span>)[:<span class="cm-number">10</span>])</span>

1
<span role="presentation">​</span>
 結果
1
[(' ', 428), ('e', 256), ('t', 170), ('i', 163), ('n', 153), ('s', 128), ('a', 124), ('r', 120), ('d', 100), ('o', 98)]

Filed Under: データクレンジング

辞書型は{key,value}

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

辞書型は{key,value}

Filed Under: Python 基本

list sort sorted 並び変え

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

listのsort関数は複雑な条件の場合sorted関数のほうがよい

 

sorted(ソートしたい配列, key=キーとなる関数, reverse=True または False)

reverseをTrueにすると降順
Falseなら昇順

2番目の要素を基に昇順に並び替えるのであれば

1
2
3
4
5
6
7
8
9
10
11
 
<span class="cm-variable">list</span> = [
    [<span class="cm-number">0</span>, 2],
    [<span class="cm-number">1</span>, <span class="cm-number">8</span>],
    [<span class="cm-number">2</span>, <span class="cm-number">10</span>],
    [<span class="cm-number">3</span>, <span class="cm-number">6</span>],
    [<span class="cm-number">4</span>, 18]
]
 
<span class="cm-builtin">sorted</span>(<span class="cm-variable">list</span>, <span class="cm-variable">key</span>=<span class="cm-keyword">lambda</span> <span class="cm-variable">x</span>: <span class="cm-variable">x</span>[<span class="cm-number">1</span>])
 

1
2
3
</code><code class="cm-s-ipython language-python">
 
 

 

Filed Under: データクレンジング

多次元を配列にするには変数に入れるだけ

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

time_data = [
[2006, 11, 26, 2, 40],
[2009, 1, 16, 23, 35],
[2014, 5, 4, 14, 26],
[2017, 8, 9, 7, 5],
[2017, 4, 1, 22, 15]
]

resolt = time_data

print (resolt)

Filed Under: Numpy

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 45
  • Page 46
  • Page 47
  • Page 48
  • Page 49
  • 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