1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

製造業のデータ分析で役に立つpandasを使った時系列データ集計加工

Posted at

はじめに

製造業の分野でデータ分析する際、製造プロセスデータ(例えば、温度や流量などの計装機器のデータ)を扱うことになろうかと思います。
そうした際、1分単位などの粒度の細かいデータは、レコード数が膨大で扱いづらいです。
そこで、pandasと呼ばれるpythonのライブラリを利用することで、簡単にデータ集計加工して、レコード数を削減することができます。

サンプルコード

例えば以下のようなcsvファイルを扱う場合

1分周期のプロセスデータ.csv
計測日時 ,温度 ,流量
2021/05/13 09:01:00 ,28.09 ,300
2021/05/13 09:02:00 ,29.02 ,200
2021/05/13 09:03:00 ,29.02 ,200

このようにpandasを活用することで、時間単位や期間指定、平均値や最大最小値の算出ができます。

import pandas as pd
FREQ_HOUR='8h' # 集計時間
FILE_PATH = './1分周期のプロセスデータ.csv' # csvファイルパス
df = pd.read_csv(FILE_PATH, index_col=0, parse_dates=True) # csv読み込み インデックス指定とインデックス列をdatetime型変換
df = df['2021-05-01':'2021-05-15'] # 期間指定
df_mean = df.groupby(pd.Grouper(freq=FREQ_HOUR)).mean() # 平均値
df_max = df.groupby(pd.Grouper(freq=FREQ_HOUR)).max() # 最大値
df_min = df.groupby(pd.Grouper(freq=FREQ_HOUR)).min() # 最小値

以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?