アメグラ2号のブログ

1980年代後半の古き良きビデオゲームのほか、オッサンの個人的備忘録

ラズパイ 温度測定データをDBへ格納(pandas解決)

f:id:game-allergy:20210416130714j:plain

前回ラズパイゼロでpandasが動かなかった件について、、、以下

game-allergy.hatenablog.com


で、なんでpandas動かないんだろ?気になって仕方がないので原因究明。

◆pandasがimportできない?

f:id:game-allergy:20210419121831j:plain

◆よくあるトラブルらしく、ここを見ろと…

f:id:game-allergy:20210419122128j:plain


以下をやってみる

pi@zero:~ $ sudo apt-get install libatlas-base-dev

◆ありゃ、インストールしてる…何かしら不足していたのか

f:id:game-allergy:20210419121732j:plain

◆実行結果(動いた)

f:id:game-allergy:20210419122558j:plain


ということでラズパイゼロだってpandasは立派に動く。当たり前か。

いや~ハマったハマった。importできない?ちゃんとpipでinstallしてるし、pip listでもpandasもある。エラーメッセージにあるpython3.7とnumpyのバージョンの確認も取れている。いったい何がおかしいのか最初はかなりハマった。よくよく読んだら…まぁ何かしらなかったってことか。

◆実行スクリプト

import sqlite3
import pandas as pd

dbname = 'TEST.db'
connection = sqlite3.connect(dbname)
cur = connection.cursor()

sql3 = 'SELECT temp, humid, time FROM HIH6130'
c3 = cur.execute(sql3)
result3 = c3.fetchall()
print(result3)

df3 = pd.DataFrame(result3,columns=["temp","humid","time"])

pd.set_option("display.max_colwidth", None)
pd.set_option("display.max_rows", None)

print(df3)

cur.close()
connection.close()

print('--------------------')
print('SeeDB; end of line')