Reputation: 21
I am very new to python and trying to complete an appointment for uni. I've already tried googling the issue (and there may already be a solution) but could not find a solution to my problem.
I have a dataframe with values and a timestamp. It looks like this:
created_at | delta |
---|---|
2020-01-01 | 1.45 |
2020-01-02 | 0.12 |
2020-01-03 | 1.01 |
... | ... |
I want to create a new column 'sum' which summarizes all the previous values, like this:
created_at | delta | sum |
---|---|---|
2020-01-01 | 1.45 | 1.45 |
2020-01-02 | 0.12 | 1.57 |
2020-01-03 | 1.01 | 2.58 |
... | ... | ... |
I want to define a method that I can use on different files (the data is spread across multiple files).
I have tried this but it doesn't work
def sum_ (data_index):
df_sum = delta_(data_index) #getting the data
y = len(df_sum)
for x in range(0,y):
df_sum['sum'].iloc[[0]] = df_sum['delta'].iloc[[0]]
df_sum['sum'].iloc[[x]] = df_sum['sum'].iloc[[x-1]] + df_sum['delta'].iloc[[x]]
return df_sum
For any help, I am very thankful.
Kind regards
Upvotes: 1
Views: 358