Commit 5a9a893a by Saroj Dhiman

Upload new file

1 parent 9bd31ff4
Showing with 43 additions and 0 deletions
import sqlite3
import pandas as pd
import csv
# creating a connection to the database
conn = sqlite3.connect('database.sqlite3')
# creating a cursor object
cur = conn.cursor()
# reading data from the CSV file
with open('cancer.csv') as f:
reader = csv.reader(f)
data = list(reader)
# print(data)
# creating a table
# query = """
# CREATE TABLE Customer(
# CustomerID INT PRIMARY KEY,
# CustomerName VARCHAR(50),
# LastName VARCHAR(50),
# Country VARCHAR(50),
# Age int(2),
# Phone int(10)
# );
# """
# cur.execute(query)
cur.execute("""CREATE TABLE CancerData ('index' INT,Year INT,nationality VARCHAR(30),
Gender VARCHAR(10),
cancer VARCHAR(10),
death INT,
age INT)"""
)
# # inserting data into the table
for row in data:
cur.execute(f"INSERT INTO CancerData ('index', Year, nationality, Gender, cancer, death, age) values {tuple(row)}")
# committing changes
conn.commit()
# closing the connection
conn.close()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!