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 500 of 2109
Fetching text from Wikipedia's Infobox in Python
In this article, we are going to scrape the text from Wikipedia's Infobox using BeautifulSoup and requests in Python. We can do it in 10 minutes. It's straightforward and useful for extracting structured information from Wikipedia pages. Prerequisites We need to install bs4 and requests. Execute the below commands to install ? pip install beautifulsoup4 pip install requests Steps to Extract Infobox Data Follow the below steps to write the code to fetch the text that we want from the infobox ? Import the bs4 and requests modules. Send an HTTP ...
Read MoreHow to select multiple DataFrame columns using regexp and datatypes
A DataFrame is a two-dimensional tabular data structure with rows and columns, similar to a spreadsheet or database table. Selecting specific columns efficiently is crucial for data analysis. This article demonstrates how to select DataFrame columns using regular expressions and data types. Creating a Sample DataFrame Let's start by creating a DataFrame from a movies dataset ? import pandas as pd # Create DataFrame from CSV movies_dataset = pd.read_csv("https://raw.githubusercontent.com/sasankac/TestDataSet/master/movies_data.csv") # Display basic info print(type(movies_dataset)) print(movies_dataset.head()) budget id original_language original_title popularity release_date ...
Read MoreProgram to find airports in correct order in Python?
Finding airports in correct order from a shuffled list of flights is a classic graph traversal problem. We need to reconstruct the travel itinerary by finding an Eulerian path through the flight connections, ensuring lexicographical ordering when multiple valid paths exist. Algorithm Overview The solution uses Hierholzer's algorithm to find an Eulerian path in a directed graph ? Build adjacency list from flight pairs Track in-degree and out-degree for each airport Find starting airport (out-degree - in-degree = 1, or lexicographically smallest) Use DFS to traverse and build the path Return reversed path for correct order ...
Read MoreProgram to check whether we can make k palindromes from given string characters or not in Python?
Suppose we have a string s and another number k, we have to check whether we can create k palindromes using all characters in s or not. So, if the input is like s = "amledavmel" k = 2, then the output will be True, as we can make "level" and "madam". Algorithm To solve this, we will follow these steps − d := a map where store each unique characters and their frequency cnt := 0 for each key in d, do if d[key] is odd, then cnt := cnt + 1 ...
Read MoreProgram to find minimum number of Fibonacci numbers to add up to n in Python?
Suppose we have a number n; we have to find the minimum number of Fibonacci numbers required to add up to n. This problem uses a greedy approach where we always pick the largest possible Fibonacci number. So, if the input is like n = 20, then the output will be 3, as we can use the Fibonacci numbers [2, 5, 13] to sum to 20. Algorithm To solve this, we will follow these steps − Initialize result counter to 0 Generate Fibonacci numbers up to n ...
Read MoreHow to create charts in excel using Python with openpyxl?
In this tutorial, we'll create Excel charts using Python's openpyxl module. We'll build a spreadsheet with tennis players' Grand Slam titles and create a bar chart to visualize the data. What is openpyxl? The openpyxl module is a powerful Python library for working with Excel files (.xlsx). Unlike the xlrd module which is read-only, openpyxl supports both reading and writing operations, making it ideal for creating charts and manipulating Excel data. Installation First, install the openpyxl module ? pip install openpyxl Creating a Spreadsheet with Data Let's start by creating a ...
Read MoreProgram to perform excel spreadsheet operation in Python?
Excel spreadsheets contain cells with values, formulas, or cell references. In Python, we can simulate this by processing a 2D matrix where each cell can contain a number, a cell reference (like "B1"), or a formula (like "=A1+A2"). Problem Understanding Given a 2D matrix representing an Excel spreadsheet, we need to evaluate all formulas and cell references to get the final computed values. Columns are labeled A, B, C... and rows are numbered 1, 2, 3... Input Matrix Output Matrix B170 35=A1+A2 770 3510 ...
Read MoreProgram to count number of operations required to convert all values into same in Python?
Given a list of integers, you can perform the following operation: pick the largest number and turn it into the second largest number. We need to find the minimum number of operations required to make all integers the same in the list. For example, if the input is nums = [5, 9, 2], the output will be 3. Here's how: pick 9 first, then make it 5, so array becomes [5, 5, 2]. Then pick 5 and make it 2, getting [5, 2, 2]. Again pick 5 and convert it into 2, resulting in [2, 2, 2]. Algorithm ...
Read MoreHow to interpolate data values into strings in Python?
We can interpolate data values into strings using various formats. We can use this to debug code, produce reports, forms, and other outputs. In this topic, we will see three ways of formatting strings and how to interpolate data values into strings. Python has three ways of formatting strings: % − old school (supported in Python 2 and 3) format() − new style (Python 2.6 and up) f-strings − newest style (Python 3.6 and up) Old Style: % Formatting The old style of string formatting has the form format_string % data. The format strings ...
Read MoreProgram to check whether we can make group of two partitions with equal sum or not in Python?
Suppose we have a list of numbers called nums, we have to check whether we can partition nums into two groups where the sum of the elements in both groups are the same. So, if the input is like nums = [2, 3, 6, 5], then the output will be True, as we can make groups like: [2, 6] and [3, 5]. Algorithm To solve this, we will follow these steps − total := sum of all elements in nums if total is odd, then ...
Read More