前提・実現したいこと
PythonでSQLiteからデータをpandasで読み込み格納し、読み込んだデータカラムに対して
applyを用いてデータの標準化をしようとしようとしていますが、エラーが発生し上手くいきません。
発生している問題・エラーメッセージ
AttributeError: 'str' object has no attribute 'mean'
該当のソースコード
Python
1#!/usr/bin/python 2# coding: UTF-8 3import sqlite3 4from contextlib import closing 5import pandas as pd 6 7dbname = 'test01.db' 8 9with closing(sqlite3.connect(dbname)) as conn: 10 c = conn.cursor() 11 df = pd.read_sql_query(sql="select * from table01", con=conn) 12 df.colum01.apply(lambda x: ((x - x.mean()) * 1 / x.std() + 0) ) 13 14conn.close()
str型がmeanを持っていないことが原因と考えたのでstr型からintへの変換を試してみましたが、
同様のエラーが出てしまい、解決できませんでした。
エラー:AttributeError: 'int' object has no attribute 'mean'
補足情報(FW/ツールのバージョンなど)
Python(3.7.3)
Pycharm

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/28 15:12