Hello I would like to be able to compare a number with another number, and if the numbers are equal to each other, then I would like to add a number to the last number. Example:
[Var]
1
1
3
4
5
I would first compare lines 1 and 2 and as they are equal to each other then I would add a number to line 2 fx 1. Then I would like to compare lines 2 and 3, and as they are going to be different(line 2 = 2 now) then the variable should not be changed
I have tried doing it like this:
Looking forward to hearing from you
Kind regards
Amdi
[Var]
1
1
3
4
5
I would first compare lines 1 and 2 and as they are equal to each other then I would add a number to line 2 fx 1. Then I would like to compare lines 2 and 3, and as they are going to be different(line 2 = 2 now) then the variable should not be changed
I have tried doing it like this:
df = pd.read_csv("newfile1.csv", dtype=str) n = 2 with open('newfile1.csv', 'r') as csv_file: csv_reader = csv.DictReader(csv_file) with open('newfile2.csv', 'w') as new_file: fieldnames = ['datetime', 'intensity'] csv_writer = csv.DictWriter(new_file, fieldnames=fieldnames, delimiter=',') csv_writer.writeheader() for line in csv_reader: for i in range(len('datetime') - 1): if 'datetime'[i + 1] == 'datetime'[i]: 'datetime'[i + 1] = 'datetime'[i] + pd.DateOffset(minutes=n) csv_writer.writerow(line)The datetime variable that i would like to change does however not change
Looking forward to hearing from you
Kind regards
Amdi
Attached Files