Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 440 of 2109
Accessing the internet using the urllib.request module in Python
The urllib.request module in Python provides a simple interface for accessing and opening URLs over the internet. This module is part of Python's standard library and supports various protocols including HTTP, HTTPS, and FTP. The primary function urlopen() makes it easy for beginners to fetch data from web resources, APIs, and other internet services. Getting Started The urllib library comes pre-installed with Python, so no separate installation is required. You can directly import and start using it in your scripts. import urllib.request Basic URL Opening The most common use case is opening and reading data from a URL. This ...
Read MoreHow to build a simple GUI calculator using tkinter in Python
Building a GUI calculator with tkinter is an excellent way to practice Python GUI development. This tutorial will guide you through creating a functional calculator with custom icons and a clean interface. Setup and Requirements First, install the required image processing library ? pip install Pillow For this project, you'll need calculator button icons. Create a folder structure like this ? +---Working Directory +---calculator.py +---assets +---Calculator ...
Read MoreHow to access and convert time using the time library in Python
The time library in Python is used to obtain time in the real world and perform various tasks related to it. You can even manipulate execution time using this module. Getting Started The time module comes packaged with Python. This means you do not have to install it separately using the PIP package manager. In order to use its various functions and methods, you must first import it ? import time Printing Current Local Time In order to print the current local time, we will be using the ctime() function. But ...
Read MoreDocumentation generation using the pydoc module in Python
The pydoc module automatically generates documentation from Python modules. The documentation can be displayed in the console, viewed in a web browser, or saved as HTML files. This built-in module helps developers access Python documentation offline and create their own documentation using docstrings. Getting Started The pydoc module comes pre-installed with Python, so no separate installation is required. You can import it directly ? import pydoc Accessing Interactive Help You can access the interactive help system using pydoc's help() function. This launches an interactive shell where you can search for documentation ? ...
Read MoreCopy and paste to your clipboard using the pyperclip module in Python
The pyperclip module allows you to programmatically copy and paste content to and from your system's clipboard. This cross-platform library works with both Python 2 and Python 3, making it useful for automation tasks and data manipulation workflows. Installation The pyperclip module is not included with Python by default. Install it using pip ? pip install pyperclip Once installed, import it into your Python script ? import pyperclip Copying Text to Clipboard Use the pyperclip.copy() function to copy text to your clipboard ? import pyperclip pyperclip.copy("Hello ...
Read MoreWrite a Python program to sort a given DataFrame by name column in descending order
Sorting a DataFrame by a specific column is a common task in data analysis. Pandas provides the sort_values() method to sort DataFrames by one or more columns in ascending or descending order. Input DataFrame Let's start with a sample DataFrame containing Id and Name columns ? Id Name 0 1 Adam 1 2 Michael 2 3 David 3 4 Jack 4 5 Peter ...
Read MoreWrite a Python function which accepts DataFrame Age, Salary columns second, third and fourth rows as input and find the mean, product of values
This tutorial shows how to write a Python function that accepts a DataFrame and calculates the mean and product of specific rows from Age and Salary columns using iloc for row slicing. Sample DataFrame Let's start with a sample DataFrame containing employee data ? import pandas as pd data = [[1, 27, 40000], [2, 22, 25000], [3, 25, 40000], [4, 23, 35000], [5, 24, 30000], [6, 32, 30000], [7, 30, 50000], [8, 28, 20000], [9, 29, 32000], [10, 27, 23000]] df = pd.DataFrame(data, columns=('Id', 'Age', 'salary')) print(df) ...
Read MoreWrite a Python program to count the total number of ages between 20 to 30 in a DataFrame
When working with Pandas DataFrames, you often need to count rows that meet specific conditions. In this case, we'll count how many ages fall between 20 and 30 using the between() method. Sample DataFrame Let's start with a DataFrame containing ID and Age columns ? import pandas as pd data = {'Id': [1, 2, 3, 4, 5], 'Age': [21, 23, 32, 35, 18]} df = pd.DataFrame(data) print(df) Id Age 0 1 21 1 2 23 2 3 ...
Read MoreWrite a program in Python to print the 'A' grade students' names from a DataFrame
Sometimes we need to filter DataFrame records based on specific column values. In this example, we'll filter a student DataFrame to show only students with 'A' grades and display their names. Sample DataFrame Let's start by creating a DataFrame with student information ? import pandas as pd data = [[1, 'stud1', 'A'], [2, 'stud2', 'B'], [3, 'stud3', 'C'], [4, 'stud4', 'A'], [5, 'stud5', 'A']] df = pd.DataFrame(data, columns=('Id', 'Name', 'Grade')) print("DataFrame is", df) DataFrame is Id Name Grade 0 1 stud1 A 1 ...
Read MoreWrite a program in Python to find the minimum age of an employee id and salary in a given DataFrame
Finding the employee with the minimum age in a DataFrame is a common data analysis task. We can use pandas boolean indexing to filter rows where the age equals the minimum age value. Problem Statement Given a DataFrame with employee data (Id, Age, Salary), we need to find the Id and Salary of the employee with the minimum age. Input DataFrame Id Age Salary 0 1 27 40000 1 2 22 25000 2 3 ...
Read More