Series.combine() — it is a series mathematical operation method. This is used to combine two series into one. The shape of the output series is the same as that of the caller series. The elements are defined by the function passed as a parameter to the
combine () method. The shape of both series must be the same, otherwise it will lead to an error.
Syntax: Series.combine (other, func, fill_value = nan)
other: other series or list type to be combined with caller series
func: Function passed as parameter which will decide from which series the element should be put at that index
fill_value: integer value of level in case of multi index
Return: b> Combined series with same shape as caller series
Example # 1:
In this example, two lists are created and converted into a series pandas using the .Series () method. The function is created using a lambda that checks which values are lower in both series and returns which is lower.
As shown in the output image, the returned row has lower values from both rows.
Example # 2:
In this example, NULL values are also passed from the
Numpy.nan method of the
Numpy.nan method. Since the series contains zero values, 5 is passed to the fill_value parameter to replace the zero values with 5. A lambda function is passed that compares the values in both series and returns a larger value.
As shown in the output, the NaN values in the series were replaced by 5 before the series was merged.
0 5.0 1 3.0 2 2.0 3 5.0 4 6.0 5 3.0 6 9.0 7 21.0 8 11.0 9 5.0 10 4.0 11 8.0 dtype: float64
For many decades, some powerful trends have been in place. Computer hardware has rap- idly been getting faster, cheaper and smaller. Internet bandwidth (that is, its information carrying capacity) has...
Pandas 1.x Cookbook: Practical recipes for scientific computing, time series analysis, and exploratory data analysis using Python, 2nd Edition....
Target knows. Apple Computer knows, too. So do LinkedIn, Netflix, Facebook, Twitter, Expedia, national and local political campaigns, and dozens of other organizations that all generate enormous eco...
Python Crash Course is the world's best-selling guide to the Python programming language. This quick and in-depth introduction to Python programming will get you started writing programs, solving prob...