Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I managed to extract data around an index number (in this case +/- 2) using the following code:

a = stim_onset[1:]

ss = [(num+1) for num,i in enumerate(zip(stim_onset,a)) if i == (False, True)]

fin = [i for x in ss for i in range(x-2, x+3 ) if i in range(len(stim_onset))]

df = data[1:].loc[np.unique(fin)]

print(df)

where stim_onset is a list of boolean False - True

df looks like this:

           0           1             2             3    

176    False  8333.912069  28698.791668  4.170312e+07

177    False  8331.456998  28695.334820  4.170315e+07

178     True  8326.858504  28695.763083  4.170319e+07

179     True  8326.862988  28704.501836  4.170322e+07

180     True  8326.804694  28700.394908  4.170325e+07

897    False  8280.768191  28618.765863  4.172740e+07

898    False  8279.306358  28621.403521  4.172744e+07

899     True  8283.315187  28619.622388  4.172747e+07

900     True  8278.514906  28631.908033  4.172750e+07

901     True  8276.656227  28619.356645  4.172754e+07

1595   False  8243.285199  28565.812841  4.175091e+07

1596   False  8244.868103  28570.760921  4.175095e+07

1597    True  8241.247154  28564.194228  4.175098e+07

1598    True  8241.372710  28578.414742  4.175101e+07

1599    True  8242.744859  28570.804845  4.175105e+07

2351   False  8218.234507  28519.885522  4.177637e+07

2352   False  8214.667367  28514.546515  4.177641e+07

2353    True  8219.288282  28523.390687  4.177644e+07

2354    True  8222.958557  28531.947153  4.177647e+07

2355    True  8221.680575  28531.938369  4.177651e+07

2906   False  8214.355719  28495.327408  4.179507e+07

2907   False  8216.021580  28500.741086  4.179510e+07

2908    True  8219.893642  28506.712604  4.179513e+07

2909    True  8220.779261  28510.848083  4.179517e+07

2910    True  8219.299492  28507.771181  4.179520e+07

3408   False  8201.423437  28479.235716  4.181197e+07

3409   False  8203.149834  28470.999897  4.181201e+07

3410    True  8201.952566  28475.888679  4.181204e+07

3411    True  8200.217201  28481.596651  4.181209e+07

3412    True  8201.037800  28475.354998  4.181211e+07

This is just a pice of a large dataset and I would like to average and calculate standard error for column 3 of df with index numbers 176-897-1595-2351-2906-3408 and for the following numbers in the block extracted. Thank you!

1 Answer

0 votes
by (41.4k points)

The below code will give you the mean and std of all the value for col 3  for those indexes.

df.iloc[np.r_[176:898, 1595:2352, 2906:3409]][3].agg(['mean','std'])

Browse Categories

...