0

e.g Standard deviation of column 'Ex_Rate_Fr' excluding rows 6-11

        Date  Ind_Prod_Fr  Ex_Rate_Fr     Cpi_Fr     Cpi_US  Log_Ex_Rate_Fr  
0    1960-01    37.698844    4.937060  10.383900  13.666246        1.596770   
1    1960-02    38.582145    4.937060  10.383900  13.666246        1.596770   
2    1960-03    38.718038    4.937060  10.383900  13.666246        1.596770   
3    1960-04    39.601339    4.937060  10.383900  13.666246        1.596770   
4    1960-05    39.635312    4.937060  10.386551  13.666246        1.596770   
5    1960-06    39.635312    4.937060  10.389201  13.574526        1.596770   
6    1960-07    36.611704    4.937060  10.391851  13.574526        1.596770   
7    1960-08    37.472357    4.937060  10.487262  13.574526        1.596770   
8    1960-09    38.333009    4.937060  10.503163  13.574526        1.596770   
9    1960-10    40.586560    4.937060  10.519066  13.666246        1.596770   
10   1960-11    41.956809    4.937060  10.550869  13.666246        1.596770   
11   1960-12    41.820917    4.937060  10.574724  13.666246        1.596770  
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • What have you tried to do? – Solomon Ucko Mar 11 '22 at 15:35
  • You would `drop` the rows (based on their index), then select the desired column, and calculate the standard deviation: `df.drop(range(6,12))['Ex_Rate_Fr'].std()` https://stackoverflow.com/questions/14661701/how-to-drop-a-list-of-rows-from-pandas-dataframe shows how to drop rows. – ALollz Mar 11 '22 at 15:36
  • @ALollz If you're answering the question, post it as an answer? – Solomon Ucko Mar 11 '22 at 15:38
  • See https://towardsdatascience.com/8-ways-to-filter-pandas-dataframes-d34ba585c1b8 – Solomon Ucko Mar 11 '22 at 15:38

1 Answers1

0

You can have a list of tuples, where each tuple represents a start and stop position (both inclusive), and use ranges and nested list-comprehension to pass them to drop before calling std:

ranges = [
    (1,2),
    (6,11),
]
stddev = df['Ex_Rate_Fr'].drop([i for x in ranges for i in range(x[0], x[1] + 1)]).std()