Home > Net >  How to take 1-x/100 of entire pandas series?
How to take 1-x/100 of entire pandas series?

Time:01-24

I want to calculate 1-x/100 for an entire pandas series? How can I do that?

x is the values in a dataframe series consisting of float numbers.

CodePudding user response:

This can be done simply

1-(pd.Series([1,2,3,4,5])/100)
#replace pd.Series([1,2,3,4,5]) with df['coumn_name'] your required series

output:

0    0.99
1    0.98
2    0.97
3    0.96
4    0.95

Do mention and example of current and desired outcomes u need and always mention code to reproduce example do keep in mind these point for your next questions

CodePudding user response:

You can make a new Series as the result, as follows:

df['result'] = df['value'].apply(lambda x: (1-x)/100)

If this is not what you want, you need to clarify what you tried and what is your expected output in the question.

CodePudding user response:

Do yu try same formula in vectorized solution?

df['result'] =  (1 - df['value']) / 100
  •  Tags:  
  • Related