I have a folder with more than 150 txt files.
To combine the data
Resulting file has a size of 320 MB. I create a database and insert combined data:
with open("resall.TXT", "r") as f:
result = f.readlines()
result = [x.split(",") for x in result]
import sqlite3 as sq3
con = sq3.connect("popular.db")
con.execute(
"""
CREATE TABLE IF NOT EXISTS popname (
id INTEGER PRIMARY KEY,
state TEXT,
sex TEXT,
year TEXT,
forename TEXT,
count INTEGER
);
"""
)
for i, (state, sex, year, forename, count) in enumerate(result):
con.execute(
"""
INSERT INTO popname VALUES (?, ?, ?, ?, ?, ?);
""",
(i, state, sex, year, forename, count.strip()),
)
con.commit()
I could not create the database because it is too large. How to reduce size of the database?