lundi 10 février 2020

For and if in dataframe column - add to another dataframe some rows before

I try to run over my data and check if one column (rain) is bigger that 0 in case if true, I need to take 100 rows before the i index,In case the i smaller than 100 I ignored it and continue the run, and added them to another dataframe. My code:

data = pd.read_csv('weather_forecast.csv')


for i in data:
    if data['rain'] > 1:
        data_before_rain = data[i-100,i-1] # Here I need to add to this dataframe the 100 rows before, 
                                           # I'm Sure that i have mistake here

print(data_before_rain) 

Example of the DataFrame data:

                  time  ghi  dni  ...  barometric_pressure  rain  sensor_cleaning
0     01/07/2018 07:14   34    0  ...                981.8   0.1                0
1     01/07/2018 07:15   34    0  ...                981.9   0.0                0
2     01/07/2018 07:16   35    0  ...                981.9   0.0                0
3     01/07/2018 07:17   36    0  ...                981.9   0.0                0
4     01/07/2018 07:18   37    0  ...                981.9   0.1                0
5     01/07/2018 07:19   38    0  ...                982.0   0.0                0
6     01/07/2018 07:20   39    0  ...                982.0   0.0                0
7     01/07/2018 07:21   40    0  ...                982.0   0.0                0
8     01/07/2018 07:22   42    0  ...                982.0   0.0                0
9     01/07/2018 07:23   43    0  ...                982.0   0.0                0
10    01/07/2018 07:24   44    0  ...                982.0   0.0                0
11    01/07/2018 07:25   45    0  ...                982.0   0.1                0
12    01/07/2018 07:26   46    0  ...                982.1   0.0                0

How can I do that?

Aucun commentaire:

Enregistrer un commentaire