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

Create a VBA to run a Query in MS Access

To create a VBA to run a query in MS Access: Copy DoCmd.OpenQuery “Query Name” Steps to Create a VBA to Run a Query in MS Access To start, assume that you have an Access database with a query called “max_sales“ Here are the steps to create a VBA to run the “max_sales” query. Step … 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

Use Pandas to Calculate Stats from an Imported CSV file

In this short guide, you’ll see how to use Pandas to calculate stats from an imported CSV file. The Example To demonstrate how to calculate stats from an imported CSV file, let’s review a simple example with the following dataset: person salary country A 40000 USA B 32000 Brazil C 45000 Italy D 54000 USA … 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

Install Package in Anaconda when Facing Connection Timeout

In this short guide, you’ll see one way to install a package in Anaconda when facing a connection timeout. Normally, you can install a Python package in Anaconda by opening the Anaconda Prompt and then typing the following command to install your desired package: Copy pip install package_name However, there could be times when you … 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