vishwajeet
vishwajeet

Reputation: 83

how to find standard deviation of pandas dataframe column containg list in every row?

i have an pandas dataframe

dd1=

     A   B   C    D   E    F   Result
     10  18   13  11  9   25  []
      6  32   27  3  18   28  [6,32]
      4   6   3   29  2   23  [29,35,87]

now i want to find std of result column by adding C column value with Result column 1st value then 2nd value of result column with C column value and so on.. and i want add that result of std and store in another column.

i want to pass the value to std function like this

for 1st row :- it will pass because it is empty.

for  2nd row :- std([6,27])=14.84,std([32,27])=3.53

after finding std just add that value and store in output column like (14.84 + 3.53)=18.37

for 3rd row :-  std([29,3])=18.38,std([35,3])=22.62,std([87,3])=59.39

output like this:- dd1=

     A   B   C    D   E    F   Result   output
     10  18   13  11  9   25  []           []
      6  32   27  3  18   28  [6,32]       18.37
      4   6   3   29  2   23  [29,35,87]    100.39

Upvotes: 0

Views: 242

Answers (1)

Rajat Jain
Rajat Jain

Reputation: 2022

Try using lambda and apply:

l = lambda x: sum([np.std([x['C'], i], ddof=1) for i in x['Result']])
dd1['output'] = dd1.apply(l, 1)

Upvotes: 1

Related Questions