右も左もわからずの自分がやってみて面白かったとか、備忘録とかにした方がいいと思った物を記事にしたものなります。もし、必要な方にいらっしゃったら、この記事が役に立てたら嬉しいと思います。 pythonのキャリアが浅すぎる私。 とりあえず、なんでもいいから最小規模のWebアプリを作りながら勉強と思っていた。 APサーバーからDBに繋ぐためのIDとPWなどをベタがきでソースに書いておいたが、 これをどこかに格納する必要があると思った。 pythonでは何で管理しているんだろう🧐
Playwright が昨年1年間で大幅パワーアップしていたので、使い方を確認したときの記録のまとめです。 ブラウザを自動操作できるということは、簡単なスクレイピングやブラウザ側のテスト自動化が簡単にできるようになります。 特に、Python での解説がまだまだ少なかったので、自分の学習を含めてまとめました。 今回は入門編ということで全体像をつかみつつ使用方法の流れを確認していただければありがたいです。 Selenium や Puppeteer を使っている方も、一度試す価値ありと思っています。 選定した理由 ブラウザのテストを Python で自動化したかったんです。 私なりの要件がありまして、非常にわがままな要件でしたが余裕ですべてクリアしました。 Python で書けること。社内で Python を使える方が多いので。pytest と連携してくれるとなおうれしい。 Docker コン
Pythonにはclickというコマンドラインパーサとして使えるライブラリがあります。同様のライブラリとして以前からargparseがありますが、clickはargparseよりももっと簡単に使えるライブラリです。 clickでコマンドラインパーサを書く例は以下になります。 # main.py import click @click.command() @click.option( "--count", type=int, default=1, required=True, help="Number of greetings.", ) @click.option( "--name", type=str, default="Your name", required=True, help="The person to greet.", ) def hello( count: int, name
概要 boto3(AWS SDK for Python)でDynamoDBをスキャンするコードです きちんとscanするために LastEvaluatedKey を使ってループする必要があります 自分用スニペットです def get_records(table, **kwargs): while True: response = table.scan(**kwargs) for item in response['Items']: yield item if 'LastEvaluatedKey' not in response: break kwargs.update(ExclusiveStartKey=response['LastEvaluatedKey'])
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>get_capture</title> </head> <body> <h3>スペースキー押下でキャプチャ取得</h3> <video id="video" width="640" height="480" autoplay></video> <canvas id="canvas" class="canvas-wrapper"></canvas> </body> <script src="{{url_for('static', filename='main.js')}}"></script> <style> /*
n,pはそれぞれnegative(ノイズ),positive(本文)を基準とした時の評価を表します。 例としてノイズ部分をN,本文をPとし,正解をT(True)、間違いをF(False)とした時にPresicionはそれぞれ以下の式です。 $$ Presicion_{[n]} = \frac{TN}{TN + FN} $$ $$ Presicion_{[p]} = \frac{TP}{TP + FP} $$ nのf値はどれだけ正確にノイズを除去できているかを、pのf値はどれだけ正確に本文を抽出できているかを評価していると考えればよいでしょう。 元のデータでの再現学習も問題無く行えました。また日本語対応版もおおよそ元論文と同程度の精度が出ています。 要点2:軽量でCPUでも1ページ0.02s程度の時間で予測できる Core i7,8コアのCPU環境でも1ページ0.02s程度の時間で予測が可能
参考 Anaconda Individual Edition Installer Archive https://repo.anaconda.com/archive/ Anaconda Documentation(Old package lists) https://docs.anaconda.com/anaconda/packages/oldpkglists/ Wikipedia(Python) https://ja.wikipedia.org/wiki/Python 更新履歴 2024/02/27:Anaconda3-2024.02-1を追加 2023/10/13:Anaconda3-2023.09-0を追加 2023/08/10:Anaconda3-2023.07-2を追加 2023/07/14:Anaconda3-2023.07-0、Anaconda3-2023.07-1を追加 2
M1 macOS で python + numpy/scipy/pandas/matplotlib/jupyterlab 環境構築のメモ(2020/12/24 時点)PythonmacOSARMM1 M1 macOS で arm64 native な python と numpy/scipy/matplotlib, Jupyter-lab など入れてデータサイエンスしたい. 現状だと x86 の時と同じやり方でインストールしようとすると, M1(arm64) の場合はコンパイルがコケたりなどしてうまく行きません (pip とか, macports 経由とかでインストールとか) 例えば altivec(みんな知っているかな!) コンパイルフラッグが clang 未サポートで numpy ビルドできないなどの issue があります. いずれ時が解決するでしょうが, 待つのもめんどいです. ソ
はじめに 普段はC++を使っているのですが,Pythonで何気なくプログラミングをしていて,ソースコードが長くなることを避けるために関数のファイルを分割してimportをしようと思いました. 同じことで困る人もいると思ったので,素早く解決できることを願います.短気な方はこちらへジャンプしてください. 他のコードからもimportすることを見越して, $ tree . ├── dir1 │ ├── mod1.py │ ├── mod2.py │ └── mod3.py └── dir2 └── main.py のようなフォルダ構造でやろうと思っていました. また,書くときに面倒にならないように,dir1.mod1.func1() のようではなく,func1()と関数を使用できるようにしたかった. 問題
はじめに 最近、APIを用いて色々なデータを取得できないかを調べています。 Youtube Data APIを使用して動画の再生回数やいいね数などの情報取得する方法を調べて実践したので覚書的に記事にまとました。 参考 Youtube Data APIの使用に当たって下記を参考にいたしました。 PythonでYoutube動画検索 YouTube Data API の概要 Youtube Data API のリファレンス APIの使用準備 Youtube Data APIの登録 Youtube Data APIの取得にはまずGoogleアカウントが必要になります。 下記手順でYotube Data APIの登録を行い、APIキーを取得します。 Google Cloud Platformにアクセスした後新しいプロジェクトを作成 新たに作成したプロジェクトにチェックを入れた状態で「APIとサービ
はじめに 今回は、機械学習の一つであるアンサンブル学習のスタッキング法についてのいいチュートリアルをKaggleで見つけたので共有します。 目的は、様々なパラメータからタイタニック号事件の生存を予測することです。 原文:Introduction to Ensembling/Stacking in Python お手元で試しながら読む場合は、先にKaggleからデータをダウンロードしてください。 データ入手方法:【Kaggle初心者入門編】タイタニック号で生き残るのは誰? Introduction 原文を呼んでください。 要は、「スタッキング法でのアンサンブル学習は、機械学習において良い精度を出すよ。」って書いてあります。 機械学習において、単一の学習器をそのまま使うのではなく、複数の学習器を組み合わせることで、予測エラーを小さくする手法をアンサンブル学習といいます。 アンサンブル(混合学習
はじめに User Sterams APIを前提としたtweepyでbotを作っていました。 User Streams API廃止と聞いて凹んでましたが bottleを使ってちょっと頑張ればAccount Activity APIに対応できるんじゃないかと思って 実装してみました。 何をするか 開発者アクセス権の登録 アプリの登録 開発環境の登録 Herokuとかでアプリを登録 bottle本体を実装 webhook用URLをツイッター認証する webhook用URLにwebhook登録したいユーザーを登録する 1-3はこちらを参考に。(結構めんどい) https://qiita.com/sbtseiji/items/7957de5db0987d9a6891 4はHeroku + bottleで適当にググると見つかります。 本記事では5以降を説明します。 5.bottle本体の実装 認証用
やったこと Slack APIを使ってみたかったので,Appの作成プロセスを最初からまとめておく. コンテンツ Slack Appを任意のワークスペースにインストール. Python3でSlack APIを使ってbotを動かせるようにする. 参考資料 https://api.slack.com/start/overview https://api.slack.com/start/building https://slack.dev/python-slackclient/index.html https://github.com/slackapi/python-slackclient 環境 MacOS Mojave 10.14.5 Python3.7 slackclient 2.0.1 Appの作成 このURLで作成したいApp名とワークスペースを指定. 新規Appが作成される. Build
同バケット内でファイルをフォルダ間でコピー line/diagonal/hoge.csvを新たにlineフォルダ下にstraightフォルダを作成しそこにコピー import os import boto3 BUCKET_NAME = 'your_bucket' # バケット名 COPY_FROM = 'line/diagonal' # コピー元ディレクトリパス COPY_TO = 'line/straight' # コピー先ディレクトリパス] FILE_NAME = 'hoge.csv' # ファイル名 s3 = boto3.client('s3') copy_from_path = os.path.join(COPY_FROM, FILE_NAME) copy_to_path = os.path.join(COPY_TO, FILE_NAME) s3.copy_object(Bucke
執筆日時:2015.08.09 いつも皆様のブログやQita,Githubなどを参考にさせていただきありがとうございます。 1.準備 1.Twitter Appにアクセス 2.[Create New App]で新規appを作成する 3.各種keyを手に入れる Consumer Key(API Key) Consumer Secret(API Secret) Access Token Access Token Secret ※Access Levelは作成したいアプリによってAccess Levelを変更すること 2.PythonでTwitterを扱う 環境はPython3.5.1 Python上でTwitterを扱うライブラリは多々ある. 私が使ったことあるのは下の三つである. python-twitter Tweepy TwitterAPI 大抵どれも みたいな感じで大抵インストールでき
やり方 lxmlを使えばOK beautifulsoup単体ではXpath指定不可 流れ beautifulsoupでhtmlをパースして、 lxmlで変換すると、 xpath指定できる! import urllib2 from lxml import html from bs4 import BeautifulSoup data = urllib2.urlopen("http://example.com") soup_parsed_data = BeautifulSoup(data, 'html.parser') lxml_coverted_data = html.fromstring(str(soup_parsed_data)) # あとはお好きにどうぞ lxml_coverted_data.xpath('xxx/yyy/...')
PythonのTkinterを使うことが多くなってきましたが,(私好みの)ほしい情報がまとまっているサイトがあまりなかったので,まとめていこうと思います. なお、Tkinterの勉強会をしたときにPython3系で作った資料が出てきたので、 ご興味のある方はどうぞ。 https://nnahito.gitbooks.io/tkinter/content/ *はじめに 私は手続き型人間です. オブジェクト指向は一切使いません. 得意言語はBASICとperlという,絶滅危惧種です. なので,オブジェクト指向最高!MVC最高!!と言われている方には,馴染まない,馴染めない書き方をしていると思いますので,ご了承ください. *そもそもTkinterとはなんぞや? PythonでGUIを組むことのできるツールキットのことです. これによって,PythonスクリプトをGUI形式で実行することができます
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く