'Vector from other two vectors pandas python [duplicate]
I can't find solution for my problem. I have two vectors pandas.Series type T = [a1, a2, a3,....,an] M = [b1, b2, b3,...bn] I need to create new vector in which every element should be the minimum between two elements in the given vector. It should looks like new_vector = [min(a1, b1), min(a2, b2), ....min(an, bn)
Is this possible with the functions in pandas?
Solution 1:[1]
Yes, can use pandas min() function to return lowest value per element position
Minimum Value Comparing Each Element of Pandas Series
import pandas as pd
T = pd.Series([6,7,4,1,4,1,6,8,0])
M = pd.Series([5,3,8,1,3,7,1,7,1])
new_vector = pd.DataFrame([T,M]).min()
print(new_vector)
Results:
idx minValue
0 5
1 3
2 4
3 1
4 3
5 1
6 1
7 7
8 0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stephan |
