Код: Выделить всё
import pandas as pd
import sqlite3
MAX_CHUNKSIZE = 6000000
# Connect to the SQLite database with a timeout
connection = sqlite3.connect('RideShare.db', timeout=10)
# Load the CSV file into a DataFrame
chunks = pd.read_csv('RideshareSample.csv', chunksize=MAX_CHUNKSIZE)
# Process the CSV file in chunks
for chunk in chunks:
# Strip whitespace from column names
chunk.columns = chunk.columns.str.strip()
chunk['Trip.Start.Timestamp'] = pd.to_datetime(chunk['Trip.Start.Timestamp'])
# Ensure the datetime conversion was successful before accessing .dt.hour
if chunk['Trip.Start.Timestamp'].isnull().all():
print("Datetime conversion failed for the entire chunk")
else:
chunk['Time.24H'] = chunk['Trip.Start.Timestamp'].dt.hour
chunk['Time.Of.Day'] = chunk['Time.24H'].apply(categorize_time_of_day)
# Write each chunk to the SQL table
chunk.to_sql('RideShareChicago_Final', connection, if_exists='append', index=False)
# Create a cursor object
cursor = connection.cursor()
Буду благодарен за любую помощь:'))
Вот моя ошибка:
Код: Выделить всё
sqlite3.OperationalError: table RideShareChicago_Final has no column named Time.24H
частичный код
нечастичный тестовый код с меньшим CSV-файлом
Подробнее здесь: https://stackoverflow.com/questions/787 ... nks-pandas