I am trying to apply some mathematics operation in each entry of csv rowwise.
This is my dataset(example):
00000 101000 102000 103000 #(these are headers)
1 2 3 4
2 3 4 5
3 4 5 6
2 4 6 8
1 2 3 5
My dataset consists more than 560 columns. I want to apply following idea to my dataset and create a new dataset:
1. In each entry of csv(rowise) apply new_entry = current_entry + (previous_entry + next_entry)/2
2. skip this operation for first and last entry
So what I want is >> row first row 1 2 3 4 >> 2 becomes 2+ (1+3)/2 = 4 and 3 becomes 3 + (2 + 4)/2 = 6. I want to apply this idea to all entries except first and last columns.
My new dataset will be :
00000 101000 102000 103000
1 4 6 4
2 6 8 5
3 8 10 6
2 8 12 8
1 4 6.5 5
I did this in python:
# X is my dataset
for i in range(1, len(X) - 1):
X.iloc[i, :] = (X.iloc[i - 1, :] + X.iloc[i + 1, :]) / 2
print(X.head())
Instead of adding old previous value, it adds new value to next value.
Can I get little assists? Thank you