Get the Current, Previous and Next-Day Dates in Python

To get the system dates with the timestamps in Python (check case 2 below to get the dates without the timestamps): Current Date: Copy import datetimecurrent_date = datetime.datetime.today()print(current_date) Previous Date: Copy import datetimeprevious_date = datetime.datetime.today() – datetime.timedelta(days=1)print(previous_date) Next-Day Date: Copy import datetimenext_day_date = datetime.datetime.today() + datetime.timedelta(days=1)print(next_day_date) Case 1: System Dates with the Timestamps Here is … Read more

Create a Database in Python using sqlite3

In this guide, you’ll see how to create a database in Python using sqlite3, including the steps to: The Steps Step 1: Create the Database and Tables In this step, you’ll see how to create: Where the columns to be added to the 2 tables are: Table Name Column Name Column Format products product_id Integer … Read more

How to Import a CSV File into Python using Pandas

To import a CSV file into Python using Pandas: Copy import pandas as pd df = pd.read_csv(r”Path where the CSV file is stored\file_name.csv”) print(df) The Example To begin with a simple example, suppose that you have the following data stored in a CSV file (where the file name is “my_products“): product brand price Computer A … Read more

How to Connect Python to SQL Server using pyodbc

To connect Python to SQL Server using pyodbc: Copy import pyodbcconn = pyodbc.connect( “Driver={SQL Server};” “Server=server_name;” “Database=database_name;” “Trusted_Connection=yes;”)cursor = conn.cursor()cursor.execute(“SELECT * FROM table_name”)for i in cursor: print(i) The Example Let’s review a simple example, where: product_id product_name price 1 Laptop 1100 2 Printer 200 3 Keyboard 80 4 Monitor 450 5 Tablet 300 Steps to Connect … Read more

Connect Python to Oracle Database using cx_Oracle

To connect Python to an Oracle database using cx_Oracle: Copy import cx_Oracledsn_tns = cx_Oracle.makedsn(“Host Name”, “Port Number”, service_name=”Service Name”)connection = cx_Oracle.connect( user=r”User Name”, password=”Personal Password”, dsn=dsn_tns)cursor = connection.cursor()cursor.execute(“SELECT * FROM database.table”)for row in cursor: print(row)cursor.close()connection.close() Steps to Connect Python to Oracle using cx_Oracle Step 1: Install the cx_Oracle package To start, install the cx_Oracle package … Read more

Connect Python to MS Access using Pyodbc

In this short guide, you’ll see how to connect Python to MS Access using pyodbc. Here are the steps: Steps to Connect Python to MS Access Step 1: Install the Pyodbc package To start, install the pyodbc package that will be used to connect Python to Access: Copy pip install pyodbc Tip: Before you connect Python … Read more

Install a Package in Python using PIP

You can install a Python package by opening the Windows Command Prompt, and then typing this command: Copy pip install package_name Note that the above method would only work if you already added Python to Windows path. Don’t worry if you don’t know what it means, as you’ll see the full steps to install a … Read more