How to multiply pandas series by value?
I have a pandas series object and I want to multiply based on the value
eg:
s = pd.Series([1,2,3,4,5,6,7,8,9,10])
how can i multiply it so i can get a series object containing only elements of greater or lesser x value.
+3
Paco bahena
source
to share
2 answers
I assume you are referring to boolean indexing in the series.
More x
:
x = 5
>>> s[s > x] # Alternatively, s[s.gt(x)].
5 6
6 7
7 8
8 9
9 10
dtype: int64
Less x
(i.e. below x):
s[s < x] # or s[s.lt(x)]
+3
Alexander
source
to share
Assuming that by "large or by x
" you mean "not equal x
", you can use boolean indexing:
s[s!=x]
+1
DyZ
source
to share