Import pandas as pd – Getting Started with Pandas

In this short guide, you’ll see how to get started with Pandas. To begin, install Pandas using this command: Copy pip install pandas Import pandas as pd In order to use the Pandas package in Python, you’ll need to type “import pandas as pd” at the top of your code. You’ll then be able to … Read more

Import numpy as np – Getting Started with NumPy

In this short guide, you’ll see how to get started with NumPy. First, install NumPy using the command: Copy pip install numpy Import numpy as np To use the NumpPy package, you’ll need to type “import numpy as np” at the top of your code. You’ll then be able to use NumPy functions and objects … Read more

Filter Python List based on Conditions

Here are 5 ways to filter a Python list based on conditions: 1. Filter Numbers Greater Than a Threshold: Filter numbers greater than 20: Copy numbers = [7, 25, 9, 30, 15] # Filter numbers greater than twenty filtered_result = [n for n in numbers if n > 20] print(“Numbers greater than 20:”, filtered_result) The … Read more

Convert Text to PDF in Python

The ‘reportlab‘ library can be used to convert text to PDF in Python. If you haven’t already done so, install the reportlab library using this command: Copy pip install reportlab Examples of Converting Text to PDF in Python Example#1: Single SHORT Sentence to PDF The following script can be used to convert a single short … Read more

Read JSON Files using Python

The ‘json‘ module can be used to read JSON files in Python. In this short guide, you’ll see several examples of reading JSON files using Python. Example of Reading a JSON File in Python Here is an example of a simple JSON file called example.json: To read that JSON file using Python: Copy import json … Read more

Access and Modify Excel Files using Python

The OpenPyXL package can be used to access and modify Excel files in Python. In this short tutorial, you’ll see how to use this package to access and modify cells in Excel. Steps to Access and Modify Excel Files using Python (1) Installation To install the OpenPyXL package, use the following command: Copy pip install … Read more

Schedule a Task using Python

The ‘schedule‘ library can be used to schedule a task in Python. The command to install the ‘schedule‘ library is: Copy pip install schedule (1) To schedule a task in Python to run every day (for example, at 10:00 am every day): Copy import schedule import time def daily_task(): print(“This task runs every day”) # … Read more

How to Delete a File using Python

The ‘os‘ module can be used to delete a file in Python: Copy import os file_path = r”Path where the file is stored\file_name.file_extension” os.remove(file_path) Example of Deleting a File using Python (1) Let’s suppose that a file called ‘Products‘ is stored in a ‘Test‘ folder, where the full file path is: C:\Users\Ron\Desktop\Test\Products.csv (2) To delete … Read more

Check if a Substring Exists in a String in Python

Here are 2 ways to check if a substring exists in a string in Python: (1) Using the “in” keyword: Copy my_string = “This is an example of a string” my_substring = “example” if my_substring in my_string: print(“Substring found”) else: print(“Substring not found”) The result: (2) Using the “find()” method: Copy my_string = “This is … Read more

How to Append Data to an Existing File using Python

To append data to an existing file using Python: Copy # The new data to be appended new_data = ” This is the additional data to be added to the file” # File path, including the r letter before the path to avoid unicode errors file_path = r”path to file\file_name.file_extension” # Opening the file in … Read more