Python Forum
reduce time series based on sum condition - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: reduce time series based on sum condition (/thread-36863.html)



reduce time series based on sum condition - amdi40 - Apr-06-2022

Hello i am trying to reduce the amount of zeros in a timeseries as i only need a period of 24 hour without rain before the condition does not change
The script so far looks like this, but the amount of time it takes to run through this is way too long. Is there someway i can make it faster?
import numpy as np
import pandas as pd
df_regn = pd.read_csv('rain_series_raw.csv', parse_dates=True, index_col=0, sep=",")
n_sim = len(df_regn)  # Antal tidskridt der skal simuleres
total = np.zeros((n_sim))
df = np.zeros((n_sim))
for i in range(1, n_sim):
    total[i] = sum(df_regn.iloc[i:i - 1400, 0])
    if total[i] > 0.1:
        df[i] = df_regn[i]
    else:
        df[i] = 5001

np.savetxt("regn23.csv", total)