Python Articles

Page 116 of 855

Get Financial Data from Yahoo Finance with Python

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

Trading, investing, and other financial professionals need access to financial data since investment research is reliant on it. Yahoo Finance, which offers up-to-date market statistics, news, and analysis, is one of the most well-known sources of financial information. Python is a robust and flexible programming language that can be used to extract financial data from Yahoo Finance, so in this article, we'll be utilizing the yfinance package to do just that. Installation and Setup Before we get started, we need to install the yfinance library, which allows us to access Yahoo Finance data from Python. We can install ...

Read More

How to Resample Time Series Data in Python

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 4K+ Views

Time series data is a sequence of observations collected over time at regular intervals. This data can be of any domain such as finance, economics, health, and environmental science. The time series data we collect can sometimes be of different frequencies or resolutions, which may not be suitable for our analysis and data modeling process. In such cases, we can resample our time series data by changing the frequencies or resolution through either upsampling or downsampling. Understanding Resampling Resampling involves changing the frequency of time series observations. Upsampling increases frequency (daily to hourly), while downsampling decreases frequency (daily ...

Read More

How to Multiply All Items in a Tuple in Python

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 4K+ Views

In Python, tuples are immutable sequences that can contain a collection of elements. We can multiply all the items in a tuple using various methods like using a for loop, using the reduce() function from the functools module, and the math.prod() function. In this article, we will explore all these methods to multiply all items in a tuple in Python. Using for Loop This method is straightforward and easy to understand. It involves iterating over each item in the tuple and multiplying them one by one using a for loop. Syntax for item in my_tuple: ...

Read More

How to Group Strings on Kth character using Python?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 483 Views

In Python, grouping strings based on their Kth character is a common string manipulation task. We can accomplish this using several approaches: regular dictionaries, defaultdict from collections, and itertools.groupby(). Each method offers different advantages depending on your specific needs. Method 1: Using a Dictionary The simplest approach uses a regular dictionary to group strings by their Kth character. We manually check if a key exists before adding strings to the corresponding group. Example Here's how to group strings by their 2nd character using a dictionary ? def group_strings_on_kth_char(strings, k): grouped_strings ...

Read More

How to Get the Nth Word in a Given String using Python?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 2K+ Views

Extracting specific words from a string is a common programming task. Python provides several approaches to get the Nth word from a string, including split() method, regular expressions, and custom delimiters. Using split() Method The simplest approach is splitting the string into words and accessing by index ? Syntax words = string.split() nth_word = words[n-1] # n is 1-based index Example def get_nth_word_split(string, n): words = string.split() if 1

Read More

Python - Leaf and Non-Leaf Nodes Dictionary

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 616 Views

Dictionary is an important data structure in Python which consists of key-value pairs. A nested dictionary can represent tree-like structures with nodes, where some nodes are leaf nodes (terminal nodes with no children) and others are non-leaf nodes (internal nodes with children). In this article, we will explore different approaches to identify and manipulate leaf and non-leaf nodes in Python dictionaries. What are Leaf and Non-Leaf Nodes? In tree-like dictionary structures, nodes are categorized based on whether they have children ? Leaf node: A node that does not have any child nodes. These are terminal nodes ...

Read More

Python - Lambda function to find the smaller value between two elements

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 523 Views

Lambda functions are anonymous functions in Python that provide a concise way to write small operations without defining a full function. In this article, we'll explore different methods to find the smaller value between two elements using lambda functions. Using Conditional Expression (if-else) The most straightforward approach uses Python's conditional expression within a lambda function ? # Direct lambda with conditional expression smaller = lambda a, b: a if a < b else b a = 45 b = 24 result = smaller(a, b) print(f"The smaller number between {a} and {b} is: {result}") ...

Read More

Python - Lambda Function to Check if a value is in a List

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 2K+ Views

Lambda functions in Python are nameless functions which are useful when we want to combine multiple expressions in a single line. The lambda function is convenient when we are sure that we won't be reusing the code anywhere else in the program. In this article we will understand how to check if a value exists in a list using the lambda function combined with various built-in methods. Using The filter() Method The filter() method in Python is a built-in function which creates new elements in the list depending upon certain filter conditions. It returns a filter object which ...

Read More

Python - Kth Valid String

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 215 Views

Finding the kth valid string is a common programming problem where we need to identify the kth element from a list that meets specific string validation criteria. In this article, we'll explore multiple approaches using iteration, filter methods, list comprehensions, and the Pandas library. Understanding The Problem Statement Given a list of elements and a value k, we need to find the kth valid string. A valid string typically contains only alphabetic characters and is not empty ? data = ["", "orange", "75", "apple", "123abc", "hello"] k = 2 # Valid strings: "orange", "apple", "hello" ...

Read More

Python - Kth Index Tuple List Mean

Asif Rahaman
Asif Rahaman
Updated on 27-Mar-2026 288 Views

Finding the mean of elements at the Kth index across multiple tuples is a common data analysis task in Python. Given a list of tuples and an index K, we calculate the average of all elements at position K across the tuples. Understanding The Problem Statement Our input contains a list of tuples and the value of K representing the index position. tuples_list = [(1, 2, 3), (4, 5, 6), (7, 8, 9)] k = 1 We need to find the mean of all elements at index K=1: From tuple (1, 2, 3): ...

Read More
Showing 1151–1160 of 8,546 articles
« Prev 1 114 115 116 117 118 855 Next »
Advertisements