<jupyter_start><jupyter_text>You have to Create Database from Postgresql. Do not create the Table , following function will create the Table but not DB.- When you run this script it will create table in Postgresql and populate the all information from your Data Frame to Postgresql.- User only need to run the script and input the asking information.- User need to give exact path CSV file. (C:\\Users\\User\\Documents\\example.csv)- Default Postgresql Username : postgres.- Defaul Postgresql Password : <PASSWORD>.- If you change your username and password please use them.<jupyter_code>from platform import python_version

print(python_version())
#Import all the module that I need.
from sqlalchemy import create_engine
import psycopg2
import pandas as pd
#path         = input('Enter the Path of CSV file      : ')
#db_name      = input('Enter Database Name             : ') #prompt user for existing db name
#user_name    = input('Enter Postgres User Name        : ')
#password     = input('Enter Postges Password          : ')
#table_name   = input('Enter Table Name to Create      : ') #user naming the db table

path = r'/home/jack/Documents/Projects/Georgetown/spending_data/FY2019 DoD Contracts/all_contracts_prime_transactions_1.csv'
db_name, user_name, password, table_name = 'usaspending', 'postgres', 'welcome', 'DoD2019'

print('Connecting to Postgresql...\n')
engine = create_engine('postgresql+psycopg2://{}:{}@localhost/{}'.format(user_name,password,db_name)) #create connection to db
print('Successfully Connected to Postgres\n')
#Create Pandas DataFrame for open our csv file.
print('Creating Data Frame...\n')

chunksize = 10 ** 5
x=0

#Define function to connect db , create table and populate csv file values to Postgres Database.
def upload_DF_to_postgres(df_to_upload, table_name=table_name, user_name=user_name, password=password, db_name=db_name):
    df_to_upload.to_sql(table_name, engine, if_exists='append')
    
    
for chunk in pd.read_csv(path, engine='python', encoding='utf8', chunksize=chunksize):
        x+=1
        upload_DF_to_postgres(chunk)
        print(f"Uploaded {x} chunk")
        
print('Data Frame Successfully Created\n')
    
    
print('CSV file Successfully Uploaded to Postgres')<jupyter_output>Creating Data Frame...

Uploaded 1 chunk
Uploaded 2 chunk
Uploaded 3 chunk
Uploaded 4 chunk
Uploaded 5 chunk
Uploaded 6 chunk
Uploaded 7 chunk
Uploaded 8 chunk
Uploaded 9 chunk
Uploaded 10 chunk
Data Frame Successfully Created

CSV file Successfully Uploaded to Postgres
{'fraction_non_alphanumeric': 0.0864736215787386, 'fraction_numerical': 0.011106703689012296, 'mean_word_length': 4.365957446808511, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '164967', 'license': 'MIT', 'n_tokens_mistral': 768, 'n_tokens_neox': 726, 'n_words': 268, 'path': 'ingestion/.ipynb_checkpoints/Upload_DF_to_Postgres - Working-checkpoint.ipynb', 'repo_name': 'jlchambon/Data-Oriented-Proposal-Engine', 'size': '2519'}