My Tech Life

Memo by a Japanese Software Developer in his late 50s.

Entries from 2024-03-01 to 1 month

How to group emails by week into arrays in Python

When conducting data analysis, deciding on the unit for aggregating data is crucial. Currently, in the midst of analyzing data obtained from bulk email collection, it seems beneficial to aggregate the data on a weekly basis. Here's a sampl…

Pythonでメールを週ごとに配列にまとめる

データ分析する時に、 どの単位でデータをまとめるか。 メールの一括収集でできるデータ分析を している最中ですが、 週ごとにメールをまとめるのが よさそうでした。 これはサンプル。 dataは2次元配列として準備、 1要素目が日付、 2要素目が本文のサンプ…

Decoding Error of "Windows-1254" in Japanese during Python web scraping.

When decoding UTF-8 text, it is being detected as Windows-1254, resulting in garbled characters. detect_enc = chardet.detect(temp)['encoding'] In that case, you can add an additional condition to handle the case when the text is mistakenly…

PythonのWebスクレイピング時に日本語で「Windows-1254」デコードエラー

UTF-8のテキストをデコードする時に、 Windows-1254と判定され、文字化けする現象。 detect_enc = chardet.detect(temp)['encoding'] 仕方ないので、条件分岐をひとつ増やして対応。 elif detect_enc == 'Windows-1254': detect_enc = 'utf-8' html_content …

Python Text Analysis Pre-Processing Chart

I think you can follow this flow to prepare for the data analysis with python. Once you reach the TextAnalyzer, various statistical analyses can be conducted.

Pythonテキスト分析前準備チャート

こんな流れで読み込んでいけばいいと思います。 TextAnalyzerまで到達すれば、あとは各種分析が実施可能です。

An example of web scraping by a browser with Python.

Previously, I posted a web scraping example using urllib, but it becomes difficult to handle when there is a session involved. Using Selenium to utilize a browser makes it easier to handle sessions. In the following sample: You set URL, XP…

ブラウザとPythonを連携させてWebスクレイピング例

以前、urllibを使ったWebスクレイピング例を投稿したが、 セッションがあると、扱うのが難しくなってくる。 Seleniumを使って、ブラウザを利用すると、 セッションが扱いやすくなる。 以下サンプルでは、 xpath_listに、URL、XPATH、検索文字列、を設定する…

Fetching emails in bulk using Python (More improved version).

I've modularized the previous version of the email fetching script, focusing solely on message retrieval. I omitted the decoding and content processing, leaving those tasks to be handled in the main processing script if needed. I've also a…

pythonでメールを一括取得する(さらに改善版)

前回のメール逐次取得版をモジュール化しました。 今回は、メッセージの取得だけに特化し、 デコード処理やコンテンツ処理は省略しました。 それらの処理が必要な場合は、メイン処理側で対応すること。 モジュールのドキュメンテーションも追加。 以下のコー…

How to read .mbox files in Python (Improved Version)

As mentioned in a previous article, when you use the conventional python library method of fetching mailboxes, it seems that parsing the entire file is required, so it can take a considerable amount of time. import mailbox mbox = mailbox.m…

pythonで.mboxを読む(改善版)

通常のmailbox取得では、ファイルの全体をパース指定するようで、 とても時間がかかることは以前の記事に書いた。 import mailbox mbox = mailbox.mbox('example.mbox') for message in mbox: print("Subject:", message['subject']) mbox.close() 逐次的に…

Web Scraping with Python

With the web scraping method, you may want to collect a large amount of data independently and automate the collection. The most important thing is whether the website allows web scraping or not. You can find out by looking at the contents…

Webスクレイピング

Webスクレイピングで、 たくさんのデータを独自に収集して、 収集を自動化したい。 一番大事なのは、 サイト側がWebスクレイピングを許可しているかどうか。 サイトの ルートディレクトリにある 「robots.txt」の中身を見てみることで分かる。 https://www.y…

Counting the frequency of specific terms in emails with Python.

Assuming there is a file named "category_social.mbox" in the same folder, the following Python script counts the frequency of term occurrences using CountVectorizer, only for emails with the word "follow" in their titles. This serves as a …

特定のメールの語句の出現頻度を集計する

同じフォルダに「category_social.mbox」があると仮定して、 タイトルにワード「フォロー」が含まれているメールのみ、 CountVectorizerで語句の出現頻度を集計するPythonスクリプトです。 AIや機械学習処理の前準備になる部分です。 今回はメール読み込みで…

Analyzing Japanese text in Python: Counting tokenized words.

Here are the minimum preprocessing steps required when performing text analysis in Python: Read the text Tokenize the text Count the tokenized words Below is a sample: First, prepare the data. Refer to a Wikipedia Japanese page and store i…

Pythonで日本語分析。分かち書きした語句のカウント

Pythonでテキスト分析する時に最低限必要な前処理を記載します。 ・テキストを読み込む ・分かち書きする ・分かち書きした語句をカウントする 以下サンプルです。 まずは、データの準備です。 Wikipedia日本語版のページを参照し、 test_dir/isaac_asimov_w…

Japanese Text Processing - Tokenization in Python

When performing Japanese natural language processing in Python,I borrowed wisdom from senior bloggers, so I managed to create a process for tokenization using MeCab. I'll paste the source code at the end of this article. As a FYI in this b…

Pythonで日本語処理ー分かち書き

Pythonで自然言語処理を行うにあたり、 ブログの諸先輩方から知恵を借りて、 Mecabで分かち書きする処理を作成。 この記事の末尾にソースを貼り付けておく。 このブログでの注意点として「self.tagger.parse("")」を追加。 これがないと、不定値の解析結果が…

Troubleshooting When ASUS EEBOOK X205TA Suddenly Stops Charging

Since there is limited information available online, I'll provide it here. My family has been using the ASUS EEBOOK X205TA for several years, but suddenly the battery stopped charging. (This model has always been somewhat unstable.) Even w…

ASUS EEBOOK X205TAの充電が突然できなくなった時の対応

Webに情報が少なかったので、載せておきます。 家族がASUS EEBOOKのX205TAを数年間使っていますが、 突然バッテリの充電が突然できなくなりました。 (この機種は、ずっとイマイチ安定しない) AC電源をつないでも、充電ランプが点灯せず、 バッテリがなくな…

english post: 'cp932' codec can't encode character '\x##' in position ####: illegal multibyte sequence

'cp932' codec can't encode character '©' in position 3337: illegal multibyte sequence Exception commonly encountered when running Python on Japanese version of Windows, but almost never observed on Linux. Verify the point below before delv…

'cp932' codec can't encode character '\x##' in position ####: illegal multibyte sequence

'cp932' codec can't encode character '\xa9' in position 3337: illegal multibyte sequence Windowsで、Pythonを動かすとよく見る例外。Linuxだと見ない。 エンコード・デコードの深みを調査する前に、これを確認すること。 自分への備忘録。 スタックト…

reading .mbox file in python

With a tendency to forget things often, I've decided to open a blog to keep future memos. Over the past decade or so, my Gmail account has accumulated a lot of emails, mostly advertisements and newsletters. With such a large collection, I …

decoding mail headers in python

Memo on decoding the email header. Using the sender/from address as an example. from email.header import decode_header decoded = decode_header(message['from']) outstr = decoded[0][0].decode(decoded[0][1]) # sample: decoded[0][0] # b'Linked…

メールヘッダーのデコード

メールヘッダーのデコード部分の備忘録。 送信元を例に。 from email.header import decode_header decoded = decode_header(message['from']) outstr = decoded[0][0].decode(decoded[0][1]) # 例)decoded[0][0] # b'LinkedIn\xe3\x82\xb3\xe3\x83\xb3\xe3…

pythonでmboxを読む

物忘れが多く、今後の備忘録を書くためにブログを開設。 ここ10年ぐらいのメールがGmailにたまっている。 ほとんど広告やニュースレターだが、これだけたくさん溜まっていると、 時代ごとに何か面白い傾向でも見つかるかと、Pythonで分析したく思った。 Gmai…