yamlでスクリプトの引数やファイルパスなどを読み込む [Python][yaml]
![Thumbnail of post image 187](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/sidekix-media-FsgWEVacLU-unsplash.jpg?resize=150%2C150&ssl=1)
インストール
pip install pyyamlまずは、config.yamlを作成
# config.yamln_class: 10xml_path:/home/ubuntu/disk/xml次にconfi ...
「TXTを1つずつ読み込んで空のDataframeに結合」を繰り返す [Python][Pandas]
![Thumbnail of post image 049](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/taylor-heery-71sp4JBYO-U-unsplash-2.jpg?resize=150%2C150&ssl=1)
from pathlib import Pathdef txt_to_df(str_txt): # TXTをDataframeに変換する、何らかの処理 return dftxt_path = Path("./txt/")all_df = p ...
XML論文からキーワードを抽出し、ワードクラウドで表示[Python]
![Thumbnail of post image 055](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/xps-4TBSG2Oqu0Q-unsplash.jpg?resize=150%2C150&ssl=1)
ElsevierやSpringerなどのオンラインジャーナルは、一般的に、論文がXMLで提供されている。XMLで提供された論文からは、タイトルやアブストラクトや本文が取り出しやすいため、テキスト解析に重宝する。
今回はXM ...
現在時刻を文字列に変換[Python]
![Thumbnail of post image 068](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/mockaroon-bzLhhI3MpYY-unsplash.jpg?resize=150%2C150&ssl=1)
from datetime import datetimedatetime.now().strftime("%Y-%m-%d-%H-%M-%S")>>'2020-07-15-05-15-42'
複数のデータを空のdataframeから生成し、結合する方法[Python][Pandas]
![Thumbnail of post image 100](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/piotr-wilk-Kc-OBw1fMJg-unsplash.jpg?resize=150%2C150&ssl=1)
以下に3つのdataframe生成し、結合するスクリプトを示す。
pd.concatを使うと、dataframeを縦連結することができる。あまり使わないと思うが、axisのオプションで横連結にすることも可能だ。
setdefaultで辞書に無いキーと値をセットする[Python]
![Thumbnail of post image 055](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/sambazon-qfIVXu7nxGU-unsplash.jpg?resize=150%2C150&ssl=1)
name_list = d = {}for name in name_list: len_name = len(name) head_name = name d.setdefault(name, ()).append((len_name, ...
空のDataFrameに1行ずつデータを追加[pandas]
![Thumbnail of post image 093](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/erik-dungan-MQyCrJVFG8U-unsplash.jpg?resize=150%2C150&ssl=1)
サンプル
import pandas as pddf = pd.DataFrame()for i in range(5): tmp_series = pd.Series() df = df.append(tmp_series, ...collection.Counterで作った辞書を棒グラフでプロット[python]
![Thumbnail of post image 069](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/samuel-yongbo-kwon-wrQsfMKwElI-unsplash.jpg?resize=150%2C150&ssl=1)
import collectionsimport matplotlib.pyplot as pltl = c = collections.Counter(l)plt.bar(list(c.keys()), list(c.values())) ...
TensorDatasetで生画像をTensor化して読み込む[PyTorch]
![Thumbnail of post image 167](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/anna-sullivan-IUXR0sqs-mY-unsplash.jpg?resize=150%2C150&ssl=1)
from glob import globfrom PIL import Imageimport numpy as npimport torchimport torch.utils.data as data_utilsfrom torchv ...
複数のCSVを読み込んで一つのDataframeにまとめる[Python][Pandas]
![Thumbnail of post image 032](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/sambazon-qfIVXu7nxGU-unsplash.jpg?resize=150%2C150&ssl=1)
hogeというフォルダの中に複数のCSVが配置されているとき、
以下のコードで複数のCSVを一つのDataFrame(表)としてまとめることが可能
from glob import globimport pandas ...