回答編集履歴
2
test
CHANGED
@@ -43,3 +43,13 @@
|
|
43
43
|
# 5 6 2000-01-01 りんご 600 60
|
44
44
|
# 6 7 2000-01-01 なし 700 70
|
45
45
|
```
|
46
|
+
|
47
|
+
> ①行ごと(1, '2000-01-01', 'さくらんぼ', 100, 10)で初期値を書き込む方法(INSERT INTO)
|
48
|
+
|
49
|
+
データフレーム全体を sqlite3 の既存テーブルに追加する場合と同様にできます。
|
50
|
+
|
51
|
+
```python
|
52
|
+
# list_df.iloc[[0]] はデータフレーム(pandas.DataFrame 型インスタンス)で、list_df.iloc[0] は pandas.Series 型インスタンスです
|
53
|
+
list_df.iloc[[0]].to_sql(name='fruit_data', con=conn, if_exists='append', index=False)
|
54
|
+
```
|
55
|
+
|
1
test
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
> sqlite3.ProgrammingError: parameters are of unsupported type
|
2
2
|
|
3
3
|
既に他の方の回答にあります通り、[`sqlite3.register_adapter(type, callable)`](https://pysqlite.readthedocs.io/en/latest/sqlite3.html#sqlite3.register_adapter) を利用して、事前に変換器を登録しておきます。
|
4
|
-
```
|
4
|
+
```python
|
5
5
|
import numpy as np
|
6
6
|
|
7
7
|
sqlite3.register_adapter(np.int64, int)
|
@@ -34,8 +34,8 @@
|
|
34
34
|
df = pd.read_sql_query(query,conn)
|
35
35
|
print(df)
|
36
36
|
|
37
|
-
# id date
|
37
|
+
# id date item price quantity
|
38
|
-
# 0 1 2000-01-01 さくらんぼ 100 10
|
38
|
+
# 0 1 2000-01-01 さくらんぼ 100 10
|
39
39
|
# 1 2 2000-01-01 いちご 200 20
|
40
40
|
# 2 3 2000-01-01 ぶどう 300 30
|
41
41
|
# 3 4 2000-01-01 みかん 400 40
|