Posts

Showing posts with the label python series

Featured Post

Python map() and lambda() Use Cases and Examples

Image
 In Python, map() and lambda functions are often used together for functional programming. Here are some examples to illustrate how they work. Python map and lambda top use cases 1. Using map() with lambda The map() function applies a given function to all items in an iterable (like a list) and returns a map object (which can be converted to a list). Example: Doubling Numbers numbers = [ 1 , 2 , 3 , 4 , 5 ] doubled = list ( map ( lambda x: x * 2 , numbers)) print (doubled) # Output: [2, 4, 6, 8, 10] 2. Using map() to Convert Data Types Example: Converting Strings to Integers string_numbers = [ "1" , "2" , "3" , "4" , "5" ] integers = list ( map ( lambda x: int (x), string_numbers)) print (integers) # Output: [1, 2, 3, 4, 5] 3. Using map() with Multiple Iterables You can also use map() with more than one iterable. The lambda function can take multiple arguments. Example: Adding Two Lists Element-wise list1 = [ 1 , 2 , 3 ]

How to use Pandas Series Method top ideas

Image
Here is an example of how to use a Series constructor in Pandas. A one-dimensional array capable of holding any data type (integers, strings, floating-point numbers, Python objects, etc.) is called a Series object in pandas. Sample DataFrame Single dimension data Below is the single dimension data of Index and Value.  Index  Value  1  10                2  40  3  01  4  99 Having single value for an index is called Single dimensional data. On the other hand, when one index has multiple values, it is called multi-dimensional array.   Below is the example for Multi-dimensional array.  a = (1, (10,20)) mySeries =  pd. Series(data, index=index) Here, pd is a Pandas object. The data and index are two arguments. The  data refers to a Python dictionary of "ndarray"  and index is index of data. Generating DataFrame from single dimension data The below example shows, how to construct single dimension data (Values and Index). >>>mySeries = pd. S eries([10,20,30], index