Reputation: 23
I am trying to calculate standard deviation of "series" for each row but the problem is every row in my column has a nested list.
My data frame is like this:
number | series |
---|---|
1 | 69,1,33,1,51,13,88,75,632 |
2 | 9,1,400,1,51,13,27,5,132 |
3 | 9,1,3,1,5,13,21,5,3 |
4 | 1,1,343,1,51,13,74,27,3 |
5 | 9,1,73,1,51,13,94,75,2 |
Upvotes: 0
Views: 301
Reputation: 1885
If the series is a list
df["std"] = df["series"].apply(np.std)
If the series is a string
df["std"] = df["series"].apply(lambda x: [int(i) for i in x.split(",")]).apply(np.std)
Upvotes: 4