combine_first() is used to combine two episodes into one. The result is the union of the two rows, that is, in the case of a Null value in the caller row, the value from the passed row is taken. In case both NULL values have the same index, NULL is returned at that index.
Note. This method is different from Series.combine (), which takes a function as a parameter to determine the output value.
Syntax : Series.combine_first(other)
other: Other series to be combined with caller series. p>
Return type: Pandas series
This example creates two series from a list using the Pandas
Series () method. Some Null values are also passed to each list using Numpy
np.nan . Then both series are combined using
.combine_first () . First, the method is called series1, and the result is stored in result1, and then series2 is called similarly and stored in result2 . Both returned series are then printed to compare the results.
As shown in the output, although the same series have been combined, the output is different. This is because the
combine_first () method
combine_first () sets the priority of the first series (Caller series) earlier. If there is a zero at this position, it gets the value with the same index from the second series.
Result 1: 0 70.0 1 5.0 2 0.0 3 225.0 4 1.0 5 16.0 6 53.0 7 10.0 8 5.0 dtype: float64 Result 2: 0 27.0 1 5.0 2 2.0 3 23.0 4 1.0 5 95.0 6 53.0 7 10.0 8 5.0 dtype: float64
Efficiently perform data collection, wrangling, analysis, and visualization using Python. Recent advancements in computing and artificial intelligence have completely changed the way we understand ...
Acquire and analyze data from all corners of the social web with Python. This book is for intermediate Python developers who want to engage with the use of public APIs to collect data from social m...
Executing Data Quality Projects: Ten Steps to Quality Data and Trusted Information (TM), 2nd Edition. Execute Data Quality Projects, Second Edition presents a structured yet flexible approach to cr...
Taking into account the development of modern programming, especially the emerging programming languages that reflect modern practice, Numerical Programming: A Practical Guide for Scientists and...