Python Articles

Page 141 of 855

How to create a text input box with Pygame?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 2K+ Views

Pygame is a free and open-source library for developing multimedia applications like video games using Python. It includes graphics and sound libraries built on top of the Simple DirectMedia Layer (SDL), providing platform-independent interfaces for graphics, sound, and input handling across Windows, Mac OS, and Linux. Creating text input boxes is essential for games that need user input like player names, chat systems, or configuration settings. This tutorial shows how to build interactive text input boxes using Pygame's event handling and rendering capabilities. Basic Text Input Box This example creates a clickable text input box that changes ...

Read More

How to create an empty DataFrame and append rows & columns to it in Pandas?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 4K+ Views

Pandas is a Python library used for data manipulation and analysis. It provides an efficient implementation of a DataFrame - a two-dimensional data structure where data is aligned in rows and columns in tabular form. While data is typically imported from sources like CSV, Excel, or SQL, sometimes you need to create an empty DataFrame and build it programmatically by adding rows and columns. Creating an Empty DataFrame You can create an empty DataFrame using the pd.DataFrame() constructor ? import pandas as pd # Create completely empty DataFrame df = pd.DataFrame() print("Empty DataFrame:") print(df) print(f"Shape: ...

Read More

How to create AGE Calculator Web App PyWebIO in Python?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 434 Views

Those who wish to practice their Python skills and learn how to develop a small web app can quickly create an age calculator web app using PyWebIO. PyWebIO is a Python library that makes building interactive web applications simple without requiring knowledge of HTML, CSS, or JavaScript. This project creates a web-based age calculator that determines a user's age based on their birthdate. We'll use Python's built-in datetime module for date calculations and PyWebIO's input/output functions to create the user interface. Installation First, install the PyWebIO library using pip ? pip install pywebio ...

Read More

How to create Abstract Model Class in Django?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 3K+ Views

We will learn about how to create Abstract Model Class in Django. An abstract model class in Django is a model that serves as a template for other models to inherit from rather than being directly created or saved to the database. Abstract models allow you to define common fields and behaviors shared across multiple models in your application. In Django, you create an abstract model by defining a class that inherits from django.db.models.Model and setting abstract = True in its Meta class. When a model inherits from an abstract model, it gains all the fields and methods ...

Read More

How to create Ternary Overlay using Plotly?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 479 Views

Ternary plots are a useful way to display compositional data where three variables add up to a constant value. Plotly is a powerful plotting library that can be used to create interactive ternary plots with ease. In this tutorial, we will explore how to create a Ternary Overlay using Plotly. To create a Ternary Overlay using Plotly, we use the scatterternary trace type. This trace type creates a scatter plot on a ternary diagram, where the components A, B, and C represent the vertices of an equilateral triangle. The position of each point within the triangle represents the proportion ...

Read More

How to load and save 3D Numpy Array file using savetxt() and loadtxt() functions?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 5K+ Views

When working with 3D NumPy arrays, savetxt() and loadtxt() functions cannot directly handle them since they expect 2D arrays. To save and load 3D arrays, you need to reshape them to 2D format first, then reshape back to 3D after loading. The Problem with 3D Arrays Using savetxt() or loadtxt() with 3D arrays directly throws an error: ValueError: Expected 1D or 2D array, got 3D array instead Solution: Reshape Before Saving and After Loading The solution involves three steps: Reshape 3D array to 2D before saving Save/load using savetxt()/loadtxt() Reshape back ...

Read More

How to lowercase the column names in Pandas dataframe?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 6K+ Views

In this article, you'll learn how to convert column names and values to lowercase in a Pandas DataFrame. We'll explore three different methods: str.lower(), map(str.lower), and apply(lambda) functions. Creating a Sample DataFrame Let's start by creating a sample DataFrame to demonstrate the methods ? import pandas as pd # Create sample restaurant data data = { 'Restaurant Name': ['Pizza Palace', 'Burger King', 'Sushi Bar'], 'Rating Color': ['Green', 'Yellow', 'Red'], 'Rating Text': ['Excellent', 'Good', 'Average'] } df = pd.DataFrame(data) print("Original DataFrame:") print(df) ...

Read More

How to load a TSV file into a Pandas Dataframe?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 5K+ Views

A TSV (Tab Separated Values) file is a text format where data columns are separated by tabs. Pandas provides two main methods to load TSV files into DataFrames: read_table() with delimiter='\t' and read_csv() with sep='\t'. Method 1: Using read_table() with delimiter='\t' The read_table() function is specifically designed for reading delimited text files ? import pandas as pd # Create a sample TSV data for demonstration tsv_data = """Name Age City Salary John 25 New York 50000 Alice 30 London 60000 Bob 28 Paris 55000 Carol 32 Tokyo 65000""" # Save sample data to a TSV file with open('sample.tsv', 'w') as f: f.write(tsv_data) # Load ...

Read More

How to create a seaborn correlation heatmap in Python?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 9K+ Views

A correlation heatmap is a graphical representation that displays the correlation matrix of a dataset using colors to show the strength and direction of relationships between variables. It's an effective tool for identifying patterns and connections in large datasets. Seaborn, a Python data visualization library, provides simple utilities for creating statistical visualizations including correlation heatmaps. The process involves importing your dataset, computing the correlation matrix, and using Seaborn's heatmap function to generate the visualization. Using the heatmap() Function The heatmap() function generates a color-coded matrix showing correlations between variable pairs. It requires a correlation matrix as input, ...

Read More

Find the size of a Dictionary in Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 7K+ Views

In Python, you often need to determine the size of a dictionary for memory allocation, performance optimization, or data validation. Python provides two main approaches: counting key-value pairs using len() and measuring memory usage with sys.getsizeof(). Syntax The syntax to determine a dictionary's size is straightforward ? # Count key-value pairs size = len(dictionary) # Get memory size in bytes import sys memory_size = sys.getsizeof(dictionary) Using len() Function The len() function returns the number of key-value pairs in the dictionary ? my_dict = {"apple": 2, "banana": 4, "orange": 3} size ...

Read More
Showing 1401–1410 of 8,549 articles
« Prev 1 139 140 141 142 143 855 Next »
Advertisements