Programming Articles

Page 141 of 2547

How to Create a Hotkey in Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 8K+ Views

Hotkeys are a convenient way to automate repetitive tasks in Python programs. They allow users to perform actions quickly and easily, without having to navigate through menus or use a mouse. In this tutorial, we will discuss how to create a hotkey in Python using the keyboard library. The keyboard library provides a simple and easy-to-use API for registering hotkeys and responding to keyboard events. By creating hotkeys in your Python programs, you can enhance the user experience and improve productivity by allowing users to perform tasks quickly and efficiently. Installation Before we start, install the keyboard ...

Read More

How to Count the Number of Rows in a MySQL Table in Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 10K+ Views

Counting the number of rows in a MySQL table is a common operation when working with databases. In Python, you can use MySQL connector libraries to establish a connection and execute SQL queries. This article demonstrates two effective approaches: using the cursor's execute() method and the SQL COUNT(*) function. Database Setup For our examples, we'll use a database named insillion with a table called bikes containing the following data: mysql> SELECT * FROM bikes; +----+-------+-------+ | id | name | price | +----+-------+-------+ | 1 | Bajaj | 2543 | | 2 ...

Read More

How to Convert Pandas to PySpark DataFrame?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 6K+ Views

Pandas and PySpark are two popular data processing tools in Python. While Pandas is well-suited for working with small to medium-sized datasets on a single machine, PySpark is designed for distributed processing of large datasets across multiple machines. Converting a pandas DataFrame to a PySpark DataFrame becomes necessary when you need to scale up your data processing to handle larger datasets. This guide explores two main approaches for converting pandas DataFrames to PySpark DataFrames. Syntax The basic syntax for creating a PySpark DataFrame is ? spark.createDataFrame(data, schema) Here, data is the pandas DataFrame ...

Read More

How to Convert HTML to Markdown in Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 16K+ Views

Markdown is a lightweight markup language that allows you to write formatted text that can be easily read and understood on the web. Converting HTML to Markdown can be useful when you want to simplify content or make it more readable for documentation, blogs, or text editors. The markdownify package in Python provides a simple and efficient way to convert HTML text to Markdown format. This article demonstrates how to install and use markdownify to convert various HTML structures into clean Markdown text. Installation The markdownify module is not pre-installed with Python, so you need to install ...

Read More

How to convert CSV File to PDF File using Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 5K+ Views

In today's data-driven world, being able to convert CSV files to more presentable PDF format is a common requirement. Python provides powerful libraries that make this conversion process straightforward and efficient. This tutorial demonstrates how to convert CSV files to PDF using Python by first converting the CSV to HTML format using pandas, then converting the HTML to PDF using pdfkit. Required Libraries and Setup Before starting, you'll need to install the required libraries and the wkhtmltopdf utility ? pip install pandas pdfkit You also need to install wkhtmltopdf from: https://wkhtmltopdf.org/downloads.html Sample ...

Read More

How to convert CSV columns to text in Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 9K+ Views

CSV (Comma Separated Values) files are commonly used to store and exchange tabular data. However, there may be situations where you need to convert the data in CSV columns to text format, for example, to use it as input for natural language processing tasks or data analysis. Python provides several tools and libraries that can help with this task. In this tutorial, we will explore different methods for converting CSV columns to text in Python using the Pandas library. Approach Load the CSV file into a pandas DataFrame using the read_csv() function. Extract the desired column ...

Read More

How to convert categorical data to binary data in Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 4K+ Views

Categorical data, also known as nominal data, is a type of data that is divided into discrete categories or groups. These categories have no inherent order or numerical value, and they are usually represented by words, labels, or symbols. Categorical data is commonly used to describe characteristics or attributes of objects, people, or events, and it can be found in various fields such as social sciences, marketing, and medical research. In Python, categorical data can be represented using various data structures, such as lists, tuples, dictionaries, and arrays. The most commonly used data structure for categorical data in Python ...

Read More

How to convert a NumPy array to a dictionary in Python?

Mukul Latiyan
Mukul Latiyan
Updated on 27-Mar-2026 9K+ Views

Converting a NumPy array to a dictionary in Python is useful when you need dictionary operations like key-based lookups or when working with APIs that require dictionary inputs. This tutorial demonstrates multiple approaches to perform this conversion. Understanding NumPy Arrays A NumPy array is a table of elements (typically numbers) of the same data type, indexed by a tuple of positive integers. The ndarray class provides efficient storage and operations for multi-dimensional data. Method 1: Converting Individual Elements to Dictionary This approach flattens the array and creates a dictionary where keys are indices and values are ...

Read More

Formatting containers using format() in Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 347 Views

The format() method in Python provides powerful ways to control how containers like lists, tuples, dictionaries, and sets are displayed. This method allows you to customize alignment, padding, precision, and presentation of your data structures for better readability. Formatting Lists You can format lists by joining elements with custom separators using format() ? my_list = [1, 2, 3, 4, 5] formatted_list = ', '.join(['{}'.format(x) for x in my_list]) print(formatted_list) 1, 2, 3, 4, 5 The join() method combines the formatted numbers with a comma and space separator. Each integer value replaces ...

Read More

Emulating Numeric Types in Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 826 Views

Python includes built-in mathematical data structures like complex numbers, floating-point numbers, and integers. But occasionally we might want to develop our own custom-behaved number classes. Here, the idea of imitating number classes is put into use. We can create objects that can be used in the same way as native numeric classes by simulating them using special methods (also called "magic methods" or "dunder methods"). Basic Addition with __add__ The simplest way to emulate numeric behavior is implementing the __add__ method − class MyNumber: def __init__(self, value): ...

Read More
Showing 1401–1410 of 25,466 articles
« Prev 1 139 140 141 142 143 2547 Next »
Advertisements