for header in headers: if header in seen: seen[header] += 1 unique_headers.append(f"{header}_{seen[header]}") else: seen[header] = 1 unique_headers.append(header)
# 创建表 columns = ', '.join([f'"{header}" TEXT'for header in unique_headers]) cursor.execute(f"CREATE TABLE IF NOT EXISTS data ({columns})")
# 插入数据 withopen(csv_file, 'r', newline='', encoding='utf-8') as file: reader = csv.reader(file) next(reader) # 跳过表头 for row in reader: placeholders = ', '.join(['?'] * len(row)) cursor.execute(f"INSERT INTO data VALUES ({placeholders})", row)
条评论