-1

How can i apply functions in the one line of code as below. I want to calculate mean,STD etc etc for the data set of which link has been shared below. In the given example i have already calculated "mean" and now i want to add some code and find other functions like STD etc.

df1 = df.loc[(df.time>=171) & (df.time<=174)[['S08','S09','S41']].mean(axis=1)

click here for the dataset (CSV file) i am referring to the column names

enter image description here

In the image above i need the mean and STD (blue) but in different Dataframe not same.

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
Curious
  • 101
  • 1
  • 10

1 Answers1

1

Try this:

In [24]: df.loc[(df.time>=171) & (df.time<=174),['S08','S09','S41']].T.agg(['mean','std']).T
Out[24]:
           mean       std
17131  1.014278  0.007357
17132  1.010441  0.005698
17133  1.008947  0.006189
17134  1.006198  0.008981
17135  1.003360  0.012050
17136  1.002270  0.012952
17137  1.000827  0.014543
17138  0.999155  0.010764
17139  0.998330  0.010462
17140  0.996994  0.009813
...         ...       ...
17421  1.005489  0.068211
17422  1.054022  0.126477
17423  1.109993  0.174473
17424  1.143518  0.192038
17425  1.143594  0.168867
17426  1.126942  0.117057
17427  1.088270  0.080759
17428  1.046547  0.053798
17429  1.005698  0.025103
17430  0.981894  0.027097

[300 rows x 2 columns]
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • Thanks for this. But the results are wrong as compared to excel. How it works by the way ? – Curious Dec 06 '17 at 12:50
  • @M.irfan, your calculations in Excel don't look correct to me. Check first row in your excel list - a mean value for the three marked numbers (where each of them is greater than 1) is `0.75669`, which is wrong in terms of regular algebra – MaxU - stand with Ukraine Dec 06 '17 at 13:00
  • I agree with you. Am sorry. My answers above are wrong. But again the calculation is getting wrong on my side. Can you please have a look over it ? – Curious Dec 06 '17 at 13:12
  • @M.irfan, sorry, i don't know how may i help you further. You wanted to calculate `mean` & `std` for each row for particular columns - i've provided you an answer which does exactly that. If you need something else please open a new question with a small sample data set in text/CSV format and provide your desired data set there as well – MaxU - stand with Ukraine Dec 06 '17 at 13:15
  • Ok thank you. By the way have you checked along with excel as well. I just compared and the results are different. That's why i asked again. – Curious Dec 06 '17 at 13:22
  • @M.irfan, you have provided a part of your Excel as a screenshot. I don't see that part where: `(df.time>=171) & (df.time<=174)`, so i don't know how can i compare it – MaxU - stand with Ukraine Dec 06 '17 at 13:25
  • Oh am sorry.. I have a given a link of my complete CSV file above. Cant you access that please? Do you want me to share another CSV with results required ? – Curious Dec 06 '17 at 13:31