前提・実現したいこと
pandasのto_sqlメソッドでcomplex型のデータをデータベースに出力したいです。
以下にエラーメッセージを添付しています。
complex型がSQLで取り扱えないのであれば、実数と、虚数のjを抜かした整数値だけを保存する形にしようと思っています。
発生している問題・エラーメッセージ
ValueError Traceback (most recent call last) <ipython-input-1618-79da8563256b> in <module>() 1 #sqliteに保存 ----> 2 fftDataframe.to_sql('{table}'.format(table='tablename_new'), con_new, index=False, if_exists='replace') ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in to_sql(self, name, con, flavor, schema, if_exists, index, index_label, chunksize, dtype) 1360 sql.to_sql(self, name, con, flavor=flavor, schema=schema, 1361 if_exists=if_exists, index=index, index_label=index_label, -> 1362 chunksize=chunksize, dtype=dtype) 1363 1364 def to_pickle(self, path, compression='infer'): ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in to_sql(frame, name, con, flavor, schema, if_exists, index, index_label, chunksize, dtype) 469 pandas_sql.to_sql(frame, name, if_exists=if_exists, index=index, 470 index_label=index_label, schema=schema, --> 471 chunksize=chunksize, dtype=dtype) 472 473 ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in to_sql(self, frame, name, if_exists, index, index_label, schema, chunksize, dtype) 1502 table = SQLiteTable(name, self, frame=frame, index=index, 1503 if_exists=if_exists, index_label=index_label, -> 1504 dtype=dtype) 1505 table.create() 1506 table.insert(chunksize) ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in __init__(self, *args, **kwargs) 1265 # (this is what sqlalchemy does) 1266 sqlite3.register_adapter(time, lambda _: _.strftime("%H:%M:%S.%f")) -> 1267 super(SQLiteTable, self).__init__(*args, **kwargs) 1268 1269 def sql_schema(self): ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in __init__(self, name, pandas_sql_engine, frame, index, if_exists, prefix, index_label, schema, keys, dtype) 563 if frame is not None: 564 # We want to initialize based on a dataframe --> 565 self.table = self._create_table_setup() 566 else: 567 # no data provided, read-only mode ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in _create_table_setup(self) 1301 """ 1302 column_names_and_types = \ -> 1303 self._get_column_names_and_types(self._sql_type_name) 1304 1305 pat = re.compile('\s+') ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in _get_column_names_and_types(self, dtype_mapper) 759 dtype_mapper(self.frame.iloc[:, i]), 760 False) --> 761 for i in range(len(self.frame.columns)) 762 ] 763 ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in <listcomp>(.0) 759 dtype_mapper(self.frame.iloc[:, i]), 760 False) --> 761 for i in range(len(self.frame.columns)) 762 ] 763 ~/Applications/anaconda3/lib/python3.6/site-packages/pandas/io/sql.py in _sql_type_name(self, col) 1356 1357 elif col_type == "complex": -> 1358 raise ValueError('Complex datatypes not supported') 1359 1360 if col_type not in _SQL_TYPES: ValueError: Complex datatypes not supported
該当のソースコード
#sqliteに保存 Dataframe.to_sql('{table}'.format(table='tablename_new'), con_new, index=False, if_exists='replace')
ご教示いただけるとうれしいです。
よろしくお願いします。
補足
先程pythonのドキュメントで、
SQLite はネイティブで TEXT、INTEGER、REAL、BLOB および NULL のみをサポートしています。その他のタイプを使用したい場合はあなた自身で追加しなければなりません。detect_types パラメーターおよび、register_converter() 関数でモジュールレベルで登録できるカスタム 変換関数 を使用することで簡単に追加できます。
と書いてあるのを発見しました。
この2つを使うのがいいのでしょうか??
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。